Exceptions framework

Exceptions framework

One of the most complex task, when writing an operating system, is to deal with complex error cases that implies undoing a lot of things. In order to ease this process, we implemented several macros functions which can be seen as “new C keywords”. The source of these macros can be found here


watch (type)

This group is the main group, where the code of the function is placed. The type passed as a parameter of the watch keyword it the return type of the function.

ensure (test, return value)

The ensure keyword forces the function to return the return value if the test fails.

check (tag, test, return value)

The check keyword reroutes the current execution flow to the rescue group tagged with tag if the test failed.

panic (test)

The panic keyword hangs the current execution flow if the test failed.

rescue (tag)

This group declares a rescue tag that can be used in a check command. The execution flow doesn’t return at the end of the rescue block, and can be forced with the leave command. This is useful when multiple actions need to be unrolled, such as successive memory allocations.


The leave keyword abort the execution flow and returns the return value specified in the check keyword.