forum-msg-id-126019-edit

Original date:2015-01-07 17:54:38 Edited by: DerekParnell Subject: Re: Try/Catch

dcuny said...

I'm wondering how try/catch/finally might be implemented in Euphoria.

Setting aside, for the moment, the examination of any compelling reasons to implement this concept into the language, I suggest a much more simpler approach - maybe a more Euphoric approach I think.


  • A new procedure (let's call it 'trap_ex' for now) that takes one parameter - either the name of a routine, or a routine_id. This procedure registers an exception handler. The handler (the routine it identifies) would be a function that gets control when the run time Euphoria (back-end) calls RTFatal(). These would always be non-recoverable exceptions, meaning that after the handler has finished, the application will be terminated. Control does not return to the application.
  • Make RTFatal() callable from user written code. This effectively implements the 'throw' concept.
  • Routines that have been registered by trap_ex() will be added to a chain of such routines. RTFatal() will call each in reverse order of registration until the first of these functions return a non-zero integer. Then any further routines in the chain are not called and the application terminates immediately.
  • A new procedure (let's call it 'untrap_ex' for now) that takes one parameter - either the name of a routine, or a routine_id. This procedure deregisters an exception handler. The handler (the routine it identifies) is removed from the RTFatal() call chain.
Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu