Help with exception handling catch

Hi. I had a customer contact me about seeing the NilObjectException. When asking her where in the program she was when she saw this error, she said it has happened a couple of times on different screens. I’ve run the built app myself on many occasions and have not uncovered any errors, nor have I heard from other customers noticing the same issues, at least none have reported seeing this, and also nothing during debugging

I kind of understand why NilObjectExceptions occur and have made necessary changes in the past. I’ve even requested to see her database files for the program, and they all check out. Nothing seems amiss. I even put her files into my program’s data folder and ran the program, and nothing

I don’t fully grasp (and think may be useful) the Try…Catch blocks. Problem is, especially with her program, that I cannot tell just where this code would need to be to find the error. I also would like to embed the Try…Catch into several areas and have the program send me an email with the information about the error so I can recreate the issue. Is this possible? The sample code in the LR only says to “add your code here”. What can you enter in here to at least display in a messagebox to say what the problem is?

Try Dim d As Xojo.Core.Date Dim t As Text = d.ToText Catch e As RuntimeException If e IsA NilObjectException Then ' your code Else ' Re-raise the exception for the framework Raise e End If End Try

First, check out the App.UnhandledException event. You should certainly added exception handling code throughout your app wherever appropriate, but this is a good “last chance” place to record the error and exit gracefully.

The exception has a Stack that records the path it took before it was raised. Usually it’s too long to fit comfortably in a MsgBox, but you can grab the first few lines, or you can save it to a file that your customer can then e-mail to you.

Thanks Kem. I saw the App.UnhandledException event and was playing around with that. When I did “make” the app crash, I did get to see the report, at least a tiny bit of it

In the rest of the app, is there something similar to the Stack in App.UnhandledException that can be used to display or send me the error data? Such as

MsgBox e.Message

This was blank when I tried in one spot

Three things are important: the Message, which may be blank, the type which you can get with Introspection, and the Stack that will tell you how you got there.

Stack is a property of a RuntimeException so you can access it in any exception.

Ah! And so there is. Missed it initially :slight_smile: Thanks!