Try ... Catch ... Throw

Previous topic - Next topic

AndyH

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.

Kitty Hello

Nice idea. Easy to implement, I think.

AndyH

Cool, I was hoping it might be as there is a direct C++ equivalent.

Moru

oh yes, that would be great!

bigsofty

Exceptions are good. :)
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

Hatonastick

Oooh yes please.  Hadn't noticed this topic before now.

Kitty Hello

Code (glbasic) Select

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

FUNCTION foo:
   THROW "up"
ENDFUNCTION


Would that be OK?

Moru

Will this also catch divide by zero and other runtime errors?

MrTAToad

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';
   }