P99

◆ P99_CATCH

#define P99_CATCH (   ...)
Value:
P99_IF_EMPTY(__VA_ARGS__)()(P00_BLK_BEFORE(__VA_ARGS__ = p00_code)) \
P00_BLK_BEFORE(p00_unw = 0) \
P00_BLK_AFTER(p00_code ? (void)((P00_JMP_BUF_FILE = 0), (P00_JMP_BUF_CONTEXT = 0)) : P99_NOP)

Designate a block that is executed regardless of the exceptions that were encountered in the corresponding try block.

Remarks
The argument to P99_CATCH should be a declaration of an integer variable, most likely an int.
With a P99_CATCH clause, an exception is considered to have been caught. If you want to unwind the call stack even further you have to use P99_RETHROW.
The corresponding code will be 0 if and only if no exception occured.

The definition of the code variable can be omitted. Such a P99_CATCH without a variable can be used to catch any exception and to continue execution after the catch clause in any case:

// do some cleanup
}
// continue here regardless of what happened

There is also a "catch all" dialect of all this

// do something complicated that may fail

The ";" after the catch is just an empty statement. So this catch clause catches all exceptions, forgets the exception code and does nothing.

See also
P99_TRY
P99_THROW
P99_RETHROW
Warning
Utilities that change control flow in an unexpected way may result in the loss of some modifications that are effected on variables. A modern compiler should tell you when you are in such a situation. If it is the case you'd have to declare the variable in question with the volatile qualifier. For an explanation see P99_UNWIND_PROTECT.

Definition at line 676 of file p99_try.h.

P99_TRY
#define P99_TRY
Create a block that can catch exceptions.
Definition: p99_try.h:585
P99_NOP
#define P99_NOP
Do nothing.
Definition: p99_block.h:297
P99_IF_EMPTY
#define P99_IF_EMPTY(...)
Definition: p99_if.h:153
P99_CATCH
#define P99_CATCH(...)
Designate a block that is executed regardless of the exceptions that were encountered in the correspo...
Definition: p99_try.h:676