Next: try-catch, Up: Exception Handling [Contents][Index]
Exceptions in Poke are values of type Exception, which is a
struct defined like this:
deftype Exception =
struct
{
int<32> code;
string msg;
};
where code identifies the type of the exception, and msg
is supposed to be a textual description of the exceptional situation.
You can use codes 255 and higher for your own exceptions. For
example:
raise Exception { code = 255; msg = "double upset event" };
Exception codes in the range 0..254 are reserved for poke.
These are used in predefined exceptions which are standard, and have
specific meanings:
E_genericGeneric error.
E_out_of_boundsOut of bounds exception. This can be raised when accessing containers, like arrays and strings.
E_eofEnd of file exception. This can be raised when mapping in the IO space.
E_elemInvalid element exception. This is can be raised when accessing union fields that do not exist.
E_constraintConstraint violation exception. This is raised when a constraint exception fails while mapping or constructing a struct.
E_convConversion exception. This can be raised while casting values.
E_map_boundsOut of map bounds exception. This can be raised while modifying a mapped value in a way it would violate its declared boundary (like the size of a mapped array.)
E_mapNo map exception. This is raised when trying to map a not mapped value.
E_div_by_zeroDivision by zero exception.
E_no_iosNo IOS exception. This is raised when the IO space is accessed but there is no IO space.
E_no_returnNo return exception. This is raised when the end of a void function is reached.
E_ioGeneric IO exception.
E_io_flagsInvalid flags were tried while opening an IO device.
The exception codes of the standard exceptions are available in the
form of EC_* variables. For example, this how you would raise
an IO error with a particular message:
raise Exception { code = EC_io,
msg = "fluzo capacitator overheat impedes IO" }
Next: try-catch, Up: Exception Handling [Contents][Index]