Exceptions in Poke are values of type Exception, which is a
struct defined like this:
type 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" };
User-defined exceptions should be registered using exception_code
function. For example:
var E_my_exception = Exception {
code = exception_code,
msg = "double upset event",
};
where the E_my_exception.code is a unique number greater than or
equal to 255.
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_eof ¶End of file exception. This can be raised when mapping in the IO space.
E_elemInvalid element exception. This is raised when attempting to access 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_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 non-void function is reached.
E_ioGeneric IO exception.
E_io_flagsInvalid flags were tried while opening an IO device.
E_assertAssertion failure exception. This is raised by assert statement.
E_overflowThis exception is raised when signed overflow is detected in an arithmetic operation.
E_permThis exception is raised when some operation can’t be performed due to incorrect (lack of) permissions or capabilities. An example is writing to a read-only IO space.
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" }