Quantcast
Channel: Xojo Programming Forum - Latest topics
Viewing all articles
Browse latest Browse all 3747

Trying to test the error handling, how to raise an error?

$
0
0

As a newby, switching from the old VB6 to Xojo, I’ m quite pleased with all the new possibilities. But right now I’m struggling in testing the error handling.

I use the Introspection method as proposed in the documentation, although slightly modified in the handling.
In a method, I have a Try … Catch block as follows:

Try
' some code

Catch err As RuntimeException
  If Not Globals.HandleException(err, CurrentMethodName) Then  ' Specifies location 'CurrentMethodName'.
    ' In case handling fails (return value is 'False').
    Raise err
  End If
  
End Try

The ‘HandleException’ function uses:

Var sMsg As String = Introspection.GetType(error).FullName + " in " + source
sMsg = "An exception of type " + sMsg + " was caught."

My question now is: I want to raise an error, just to test and see what happens. So, I’ve put before the ‘Catch’ a line with:

Raise New OutOfBoundsException

But when I run the program, it stops at this line instead of handling the error using ‘HandleException’.

What am I doing wrong, or is there an other way to raise an error? In VB6 it was just a matter of adding a line ‘Err.Raise 9999’ (for example).

5 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 3747

Trending Articles