Finding an unhandled exception

Since App.UnhandledException isn’t firing - something I find unusual, but I’ll take your word for it - you’ll need to use Try/Catch to find the exception. Wrap it around the close statement. If this happens when closing the window using the close box, consider adding a button to the window temporarily:

Sub PushButton1_Action()
  Try
    Self.Close
  Catch Err As RuntimeException
    // Look at Err here
  End Try
End Sub

This should catch any deeper exception, and the stack property of Err should give you some clues.

1 Like

i guess you access a ui control which is not there anymore.

some other nil objects occur if u use a method or property at a nil object.
somehow Nil.DoSomething Nil.Text = “”

Good idea.

Yes, that’s probably the reason for the NOE.

Ok look for runtimeexception (catch all) handlers (end of methods) that may not be forwarding the exception or look for the text (parts) of the messagebox you getting.

Any reason you’ve not tried the simple “break on exceptions” menu item so Xojo breaks at the correct place?

I have worked in Realbasic, RealStudio and Xojo. “Break on Exceptions” always has been on.

Certainly, but you’ve not mentioned what happens with your exception; does it even break?

1 Like

No, it doesn’t break. The app doesn’t even quit.

use temporary in much methods at top System.DebugLog CurrentMethodName
u will know where the app was last

1 Like

The window has 2 dozen container, more than 40 classes and hundreds of methods.

start within the bounds of possibility :slight_smile:

1 Like

What does you code do if you have an exception inside App.UnhandledException itself?

Other ideas:

  • possibly you are having a Cocoa exception which can cause a method to silently exit - run your app with Console.log open and your app’s name in the search box.
  • Or, you could try making sure your app quits on exceptions: See Crash an application on NSException - #2 by Scott_Cadillac (Though, I think this already happens on High Sierra?)
  • add this line as the very first line of app.UnhandledException:
    system.debugLog "unhandled exception!!!"
    (just to prove to yourself this handler is or is not firing)
1 Like

Could it be that in the App.UnhandledException you have a NilObjectException causing it to be skipped or hard crashing?

So maybe you could put this above in the App.UnhandledException:

Var exception_type As String = Introspection.GetType(err).Fullname
system.log system.loglevelcritical, "!<>! " + CurrentMethodName + ", " + exception_type  + ", " + err.message

Then run it with Console.App open and filter on “!<>!”

My guess is that it is occurring in a control, and potentially from a declare or plugin, maybe even on a different thread, so for some reason it’s skipping the built-in Exception handling code from Xojo.

@Beatrix_Willius
I don’t see anything above so… are you returning True or False from the UnhandledException method? I’m asking because if returning False (or nothing) trying to show a window will outright fail because the app will be allowed to crash.

That’s a really good question. I don’t think I ever had the UnhandledException fire. At all. I tried with a method where I commented out the exception handler

dim f as FolderItem
f.Delete

'exception exc
'theException = new ErrorException(exc, currentMethodName)

But even there I get the normal exception behaviour.

Anyways. I wrangled with the SVN. Whatever I merged from before the NOE with the current version all is now good.

So sad… Now we’ll never know what went wrong :wink:

1 Like

Just Murphy paying a brief visit.

2 Likes

Murphy always returns… best to say hi and have a long discussion with him whenever you can.

3 Likes