Tips & Tricks: fully exploring exceptions

by Giuseppe Lanzi on 02/09/2015

Sometimes it becomes necessary to take a very in-depth look into the exceptions that may crop up in your applications. The exact error number, the stack trace, or other information can often provide the only hints for understanding a complex problem.

Applications made with InDe manage errors and fire the OnException event precisely for this reason. Nevertheless, in support I’ve seen that in some cases, this isn’t enough. In order to find out the error number and message, you do in fact need to know what type of exception was received. But what happens if your application has integrated libraries that launch exceptions of a specific type, and perhaps with special properties? It isn’t possible to get detailed information because the InDe libraries don’t contain references to that given class of exceptions.

Also, there are certain errors for which InDe assigns its own error code. This occurs because, in the portability logic of applications created with InDe, the code should tend to be the same, but the error codes are different among the various languages supported!

In order to solve the problem and get all the information you want in your application, perhaps to write it to a specific log, simply add a specialized function to your project that deals with analyzing the specialized Exception that was reported. You can achieve this by using reflection.

Once you’ve obtained the specialized object, it’s simple to read it and display the error to the user, write it to a log file, or send it by email. From here the choice is yours.

I’ve prepared a project for you, and I’ve added a custom getException library function, which, if used in the OnException event, will allow you to show the stack trace on screen or identify it. Try clicking Simulate Exception, then Customization ON OFF, and then Simulate Exception again. You’ll see that the information is different: for example, the second time you’ll have the stack trace available.

Try the project; once in a while it can be fun to launch errors 🙂

Image: Gabriele.

Leave a Comment

Previous post:

Next post: