Functions for standard exceptions and finally handlers. More...
Data Structures | |
| struct | lh_exception |
| Standard exception type. More... | |
Macros | |
| #define | defer_exit(after, release_fun, local) |
| Install a finally function that is always run. More... | |
| #define | defer(release_fun, local) |
| Install a finally function that is always run. More... | |
| #define | on_abort(release_fun, local) |
Functions | |
| void | lh_exception_free (lh_exception *exn) |
| Free an exception. | |
| lh_exception * | lh_exception_alloc_ex (int code, const char *msg, void *data, int _is_alloced) |
| Create an exception. | |
| lh_exception * | lh_exception_alloc_strdup (int code, const char *msg) |
| Create an exception. | |
| lh_exception * | lh_exception_alloc (int code, const char *msg) |
| Create an exception. | |
| void | lh_throw (const lh_exception *e) |
| Throw an exception. | |
| void | lh_throw_errno (int eno) |
| void | lh_throw_str (int code, const char *msg) |
| void | lh_throw_strdup (int code, const char *msg) |
| void | lh_throw_cancel () |
| lh_exception * | lh_exception_alloc_cancel () |
| bool | lh_exception_is_cancel (const lh_exception *exn) |
| void | lh_strerror (char *buf, size_t len, int eno) |
| Portable way to get a string error message. | |
| lh_value | lh_try (lh_exception **exn, lh_actionfun *action, lh_value arg) |
| Convert an exceptional computation to an exceptional value. More... | |
| lh_value | lh_try_all (lh_exception **exn, lh_actionfun *action, lh_value arg) |
| lh_value | lh_finally (lh_actionfun *action, lh_value arg, lh_releasefun *faction, lh_value farg) |
Functions for standard exceptions and finally handlers.
| struct lh_exception |
Standard exception type.
Don't use this directly but use the provided functions to allocate and operate on exceptions.
| #define defer | ( | release_fun, | |
| local | |||
| ) |
Install a finally function that is always run.
| release_fun | A lh_releasefun that is called on the exit of the scope, either when returning normally, or when aborting, for example when an exception is thrown. |
| local | An lh_value that is passed to the release function. |
defer always needs a scope with double braces. For example:
| #define defer_exit | ( | after, | |
| release_fun, | |||
| local | |||
| ) |
Install a finally function that is always run.
| release_fun | A lh_releasefun that is called on the exit of the scope, either when returning normally, or when aborting, for example when an exception is thrown. |
| local | An lh_value that is passed to the release function. |
defer always needs a scope with double braces. For example:
| lh_value lh_try | ( | lh_exception ** | exn, |
| lh_actionfun * | action, | ||
| lh_value | arg | ||
| ) |
Convert an exceptional computation to an exceptional value.
If an exception is thrown, exn will be set to a non-null value