Code-Adding Utility Software for Xojo

I am in the process of adding exception-handling code to the end of all of the methods and event procedures in my Xojo desktop project, which is quite large.

Does anyone know of any Code-Adding Utility that may exist for Xojo that would help me to accomplish this tedious and time-consuming task?

Many years ago, an Error-Code-Adding Utility was available for Visual Basic 6, which worked very well.

You can do some of this with IDE Scripts which can add code to the current code editor.

Typically you’d add Exception handling as narrowly as possible to handle expected Exception. Otherwise, you can use the App.UnhandledException event to catch those that get by.

Is what you’re doing different than either of these?

2 Likes

Thank you Kem. So I am adding the following code to the bottom of each and every method in the project:

Exception err As RuntimeException // Will catch any exception without discrimination
If err IsA EndException Or err IsA ThreadEndException Then
  Raise err // Re-raise the exception
End If
RuntimeErrorException(err, CurrentMethodName)

Here is the RuntimeErrorException method accociated with the code:

Public Sub RuntimeErrorException(rtError As RuntimeException, sLocation As String)
    
  Var sExceptionType As String
  If rtError IsA TypeMismatchException Then
    sExceptionType = "TypeMismatchException"
  ElseIf rtError  IsA NilObjectException Then
    sExceptionType = "NilObjectException"
  ElseIf rtError IsA OutOfBoundsException Then
    sExceptionType = "OutOfBoundsException"
  ElseIf rtError IsA StackOverflowException Then
    sExceptionType = "StackOverflowException"
  ElseIf rtError IsA IOException Then
    sExceptionType = "IOException"
  ElseIf rtError IsA RegExException Then
    sExceptionType = "RegExException"
  ElseIf rtError IsA CryptoException Then
    sExceptionType = "CryptoException"
  ElseIf rtError IsA DatabaseException Then
    sExceptionType = "DatabaseException"
  Else
    sExceptionType = "UnknownRuntimeException"
  End If
  
  System.DebugLog(sExceptionType + " at " + sLocation)
  
  Var d As DateTime = DateTime.Now
  
  WriteErrorLog(d.SQLDateTime + " " + sExceptionType + " at " + sLocation + " Version: " +  VersionData)
  
    
End Sub

Is there a way I can accomplish this globally?

You don’t need all these Else lines.

Just query class name:

dim ClassName as string = Introspection.GetType(rtError).fullname

2 Likes

Yes:

And the documentation for what Christian mentions: Introspection — Xojo documentation

1 Like

Thank you so much Kem, Christian, and Tim. Wow! What a time saver!

1 Like