Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/exceptions/defaults.cfa

    recfd758 rfd54fef  
    44#include <exception.hfa>
    55
    6 EHM_EXCEPTION(log_message)(
     6DATA_EXCEPTION(log_message)(
    77        char * msg;
    88);
    99
    10 _EHM_DEFINE_COPY(log_message, )
    11 const char * msg(log_message * this) {
     10void ?{}(log_message & this, char * msg) {
     11        VTABLE_INIT(this, log_message);
     12        this.msg = msg;
     13}
     14
     15const char * get_log_message(log_message * this) {
    1216        return this->msg;
    1317}
    14 _EHM_VIRTUAL_TABLE(log_message, , log_vt);
     18
     19VTABLE_INSTANCE(log_message)(get_log_message);
    1520
    1621// Logging messages don't have to be handled.
     
    2328        // We can catch log:
    2429        try {
    25                 throwResume (log_message){&log_vt, "Should be printed.\n"};
     30                throwResume (log_message){"Should be printed.\n"};
    2631        } catchResume (log_message * this) {
    2732                printf("%s", this->virtual_table->msg(this));
    2833        }
    2934        // But we don't have to:
    30         throwResume (log_message){&log_vt, "Should not be printed.\n"};
     35        throwResume (log_message){"Should not be printed.\n"};
    3136}
    3237
    3338// I don't have a good use case for doing the same with termination.
    34 EHM_EXCEPTION(jump)();
     39TRIVIAL_EXCEPTION(jump);
    3540void defaultTerminationHandler(jump &) {
    3641        printf("jump default handler.\n");
    3742}
    3843
    39 EHM_VIRTUAL_TABLE(jump, jump_vt);
    40 
    4144void jump_test(void) {
    4245        try {
    43                 throw (jump){&jump_vt};
     46                throw (jump){};
    4447        } catch (jump * this) {
    4548                printf("jump catch handler.\n");
    4649        }
    47         throw (jump){&jump_vt};
     50        throw (jump){};
    4851}
    4952
    50 EHM_EXCEPTION(first)();
    51 EHM_VIRTUAL_TABLE(first, first_vt);
    52 
    53 EHM_EXCEPTION(unhandled_exception)();
    54 EHM_VIRTUAL_TABLE(unhandled_exception, unhandled_vt);
     53TRIVIAL_EXCEPTION(first);
     54TRIVIAL_EXCEPTION(unhandled_exception);
    5555
    5656void unhandled_test(void) {
    5757        forall(T &, V & | is_exception(T, V))
    5858        void defaultTerminationHandler(T &) {
    59                 throw (unhandled_exception){&unhandled_vt};
     59                throw (unhandled_exception){};
    6060        }
    6161        void defaultTerminationHandler(unhandled_exception &) {
     
    6363        }
    6464        try {
    65                 throw (first){&first_vt};
     65                throw (first){};
    6666        } catch (unhandled_exception * t) {
    6767                printf("Catch unhandled_exception.\n");
     
    6969}
    7070
    71 EHM_EXCEPTION(second)();
    72 EHM_VIRTUAL_TABLE(second, second_vt);
     71TRIVIAL_EXCEPTION(second);
    7372
    7473void cross_test(void) {
    7574        void defaultTerminationHandler(first &) {
    7675                printf("cross terminate default\n");
    77                 throw (second){&second_vt};
     76                throw (second){};
    7877        }
    7978        void defaultResumptionHandler(first &) {
    8079                printf("cross resume default\n");
    81                 throwResume (second){&second_vt};
     80                throwResume (second){};
    8281        }
    8382        try {
    8483                printf("cross terminate throw\n");
    85                 throw (first){&first_vt};
     84                throw (first){};
    8685        } catch (second *) {
    8786                printf("cross terminate catch\n");
     
    8988        try {
    9089                printf("cross resume throw\n");
    91                 throwResume (first){&first_vt};
     90                throwResume (first){};
    9291        } catchResume (second *) {
    9392                printf("cross resume catch\n");
Note: See TracChangeset for help on using the changeset viewer.