GLBasic forum

Main forum => GLBasic - en => Topic started by: AndyH on 2008-Mar-25

Title: Try ... Catch ... Throw
Post by: AndyH on 2008-Mar-25
Would it be possible for GLB to support TRY ... CATCH blocks and THROW functionality for handling unexpected and expected errors?

This is not generally something you see in traditional BASIC's but you do get in most modern langauges (including VB) because it can help you to manage runtime errors quite easily.
Title: Try ... Catch ... Throw
Post by: Kitty Hello on 2008-Mar-25
Nice idea. Easy to implement, I think.
Title: Try ... Catch ... Throw
Post by: AndyH on 2008-Mar-25
Cool, I was hoping it might be as there is a direct C++ equivalent.
Title: Try ... Catch ... Throw
Post by: Moru on 2008-Mar-25
oh yes, that would be great!
Title: Try ... Catch ... Throw
Post by: bigsofty on 2008-Mar-25
Exceptions are good. :)
Title: Re: Try ... Catch ... Throw
Post by: Hatonastick on 2009-Jul-27
Oooh yes please.  Hadn't noticed this topic before now.
Title: Re: Try ... Catch ... Throw
Post by: Kitty Hello on 2009-Jul-27
Code (glbasic) Select

TRY
...
foo()
CATCH err$
...
ENDTRY

FUNCTION foo:
   THROW "up"
ENDFUNCTION


Would that be OK?
Title: Re: Try ... Catch ... Throw
Post by: Moru on 2009-Jul-27
Will this also catch divide by zero and other runtime errors?
Title: Re: Try ... Catch ... Throw
Post by: MrTAToad on 2009-Jul-28
No, it shouldn't - the throw would force the CATCH command to run, as per this C++ example :

Code (glbasic) Select
try {
      buf = new char[512];
      if( buf == 0 )
         throw "Memory allocation failure!";
   }
   catch( char * str ) {
      cout << "Exception raised: " << str << '\n';
   }