P99
|
◆ P99_TRY
Value:
/* one phase for the try, one for the finally */ \ /* Restrict the first phase to the try */ \ if (!p00_pha) \ P00_BLK_START \ P00_BLK_BEFORE(p00_jmp_push(p00_unwind_top)) \ do #define P99_UNWIND_PROTECT Unwind execution from several levels of nesting inside a function. Definition: p99_block.h:604 Create a block that can catch exceptions.
The simplest use of this feature is together with P99_FINALLY unsigned char*volatile buffer = 0; P99_TRY { buffer = malloc(bignumber); // do something complicated with buffer favorite_func(buffer); } P99_FINALLY { free(buffer); } This will ensure that the buffer allocated in If no exception occurs, the P99_FINALLY clause is always executed. Execution then continues after the clause, just as for normal code. If an exception occurs, the P99_FINALLY clause is executed (and in this case the call to An alternative way is to use P99_CATCH and to handle different exceptions explicitly. unsigned char*volatile buffer = 0; P99_TRY { buffer = malloc(bignumber); // do something complicated with buffer } P99_CATCH(int code) { switch(code) { } free(buffer); if (code) P99_RETHROW; } The difference here is that we receive the error code through the variable Here, since there is a P99_RETHROW, execution will jump to the next P99_FINALLY or P99_CATCH block on the call stack. In fact a catch clause of Would be equivalent to except that this wouldn't give access to Note that the code depending on P99_TRY must always be an entire block with
|