#ifndef FEXCEPT_BI #define FEXCEPT_BI #include "crt/setjmp.bi" #macro define_exception_type(etype) type exception_context penv as jmp_buf ptr caught as integer v as etype end type #endmacro #define init_exception_context(ec) (((ec)->penv = 0)) #macro init_exceptions(etype) define_exception_type(etype) dim shared as exception_context ptr the_exception_context the_exception_context = new exception_context the_exception_context->penv = 0 #endmacro #macro Try() : dim as jmp_buf ptr exception__prev dim as jmp_buf exception__env exception__prev = the_exception_context->penv the_exception_context->penv = @exception__env if (setjmp(@exception__env) = 0) then #endmacro #define EndTry end if #macro exception__catch(action) elseif action then the_exception_context->caught = 1 #endmacro #define EndCatch elseif the_exception_context->caught = 0 then : the_exception_context->penv = exception__prev : Throw( the_exception_context->v ) #define Catch(e) exception__catch(((e) = the_exception_context->v)) #define CatchElse exception__catch((1=1)) /' Try ends with do, and Catch begins with while(0) and ends with */ /* else, to ensure that Try/Catch syntax is similar to if/else */ /* syntax. */ /* */ /* The 0 in while(0) is expressed as x=0,x in order to appease */ /* compilers that warn about constant expressions inside while(). */ /* Most compilers should still recognize that the condition is always */ /* false and avoid generating code for it. '/ #define Throw(eee) the_exception_context->v = eee : longjmp(cast(jmp_buf ptr,the_exception_context->penv), 1) #endif '/* CEXCEPT_BI */