Search code examples
basicrealbasicxojo

Try Catch statement realBasic


I am trying to wrap up simple statement within try catch. Problem is that all examples that I was able to find talk about the errors which are predefined.

I need a generic error, similar to try/catch in C#.


Solution

  • For a generic try catch you can do this:

    try
    
      ...put some code here
    
    catch
    
      ...do something for ANY exception here.
    
    finally
    
      ...code here that runs IF an exception occurs
    
    end try
    

    The catch section has optional parameters to catch certain types of errors (the examples you've seen). The first paragraph gives the definition at http://docs.xojo.com/index.php/Try

    Try
    
    // Your code
    
    Catch [ErrorParameter] [As ErrorType]
    
    //exception handlers
    
    [ Finally ]
    
    //code that executes even if runtime exceptions were raised
    
    End [Try]