[Ann] Exception Handler

If you have the following code in a method you will get a NilObjectException:

dim f as FolderItem
f.Delete

When using the Exception Handler with this code:

dim f as FolderItem
f.Delete

exception exc
  theException = new ErrorException(exc, currentMethodName)

then you will get a file with the name of session log in the Application Support folder and information about the NilObjectException:

2024-09-27 08:29:40 An error happened:

2024-09-27 08:29:40 Class/Method: Window1.Method2

2024-09-27 08:29:40 Time: 27. Sep 2024 08:29:40 258275992

2024-09-27 08:29:40 Type of Error: NilObjectException

2024-09-27 08:29:40 Error Number: 0

2024-09-27 08:29:40 Error Message:

2024-09-27 08:29:40 --------------------------

2024-09-27 08:29:40 Stack:

2024-09-27 08:29:40

Sub Window1.Window1.Method2(Window1.Window1)

Sub Window1.Window1.Method1(Window1.Window1)

Sub Window1.Window1.Button1_Pressed(Window1.Window1, DesktopButton)

Sub Delegate.IM_Invoke(DesktopButton)

Sub AddHandler.Stub.20()

Sub DesktopApplication._CallFunctionWithExceptionHandling()

2024-09-27 08:29:40 Stack done

Available at Xojo + Alfred

6 Likes

You should consider removing the duplicate names like this:

Window1.Window1.Method2

That can just be shown as

Window1.Method2

1 Like

I have been using this code for over 10 years and never noticed that. I’ll fix the bug in the next days.

Handy, thank you for sharing!

Technically it’s not a bug. Implicit instances of Windows are rendered something like this:

Module Window1
  Global Function Window1() as Window1
End Module

The first time Window1() is called, it creates the new instance and stores it for the next time.

That’s why the exception says

Window1.Window1.Method2()

2 Likes