int main(void)
{
    static const except_id_t match[] = { { 1, 1 }, { 1, 2 } };
    except_t *ex;

    /*
     * Nested exception ``try blocks''
     */

    /* outer */
    except_try_push(match, 2, &ex);
    if (!ex) {
        /* inner */
        except_try_push(match, 2, &ex);
        if (!ex) {
            top_level();
        } else {
            /* inner catch */
            printf("caught exception (inner): \"%s\", s=%ld, c=%ld\n",
                    except_message(ex), except_group(ex), except_code(ex));
            except_rethrow(ex);
        }
        except_try_pop();
    } else {
        /* outer catch */
        printf("caught exception (outer): \"%s\", s=%ld, c=%ld\n",
                except_message(ex), except_group(ex), except_code(ex));
    }
    except_try_pop();
    except_throw(99, 99, "exception in main");
    return 0;
}
示例#2
0
void *except_alloc(size_t size)
{
    void *ptr = get_alloc()(size);

    if (ptr == 0)
	except_throw(XCEPT_BAD_ALLOC, 0, "out of memory");
    return ptr;
}
示例#3
0
static void bottom_level(void)
{
    char buf[256];
    printf("throw exception? "); fflush(stdout);
    fgets(buf, sizeof buf, stdin);

    if (buf[0] >= 0 && toupper(buf[0]) == 'Y')
	except_throw(1, 1, "nasty exception");
}