Exceptional behaviour– I think not!

Take a standard windows forms application in .NET, and modify the start up code to the following.

exceptional

If you run the code on a x64 architecture you see the exception being thrown, but the Form is displayed nevertheless. If you run on x86, the exception causes the application to exit and moreover you can catch the exception if you wrap the call to Application.Run inside a try…catch…

I came across the explanation while I was researching Windows SEH on this blog. The older versions of the OS had difficulty propagating structured exceptions across the re-entry from kernel mode which happens in order to raise the Load event. I guess the lesson to learn is to always keep an eye on the Output window when you are running your application in order to verify that you are seeing the exceptions you expect… if you don’t, you might find exceptions being silently swallowed, which could lead to all kinds of unexpected corruption in your application’s state.

Advertisements
This entry was posted in Computers and Internet. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s