This is a mirror of official site: http://jasper-net.blogspot.com/

Using exception handling in VC++

| Wednesday, April 21, 2010
As every Windows user, you probably have suffered more than one time from this annoying occurrence: You work on application, and then suddenly, without any reasonable explanation, the application crashes, and system message box appears on the screen, telling you that the application going to be terminated. This crash window varies from one operating system to another: In Windows 98, for example, the following text is displayed: 'This program has performed an illegal operation and will be shut down'. Windows 2000 and Windows NT, as opposed to previous versions of Windows, display the details of the problem that caused the exception. For example: 'The instruction at "0x00401000" referenced memory at "0x00000000" The memory could not be written.'
However, there is one common thing in all Windows operating system: In such event, you lose all your work you have done since the last save operation.

Background

Around a years back, while writing a huge app, (consisting around 93 internal projects), where there were around 15 threads were running constantly and communicating with each other, I'd faced several problems. Most of the time at the middle of the program, it was crashed.

This problem is mostly occurred due to a bug in the application itself, or in the one of the components or libraries of the operating system. luckily, the programmer has the ability to avoid this kind of annoying crashes, by applying a simple exception handling mechanism.

Borland Delphi development tool is a good example of effective crash handling: The executables created by this tool has a special build-in exception handling routines, so whenever an exception is occurred in a Delphi program, a special dialog-box of Delphi is displayed. This dialog-box contains some information about the problem that caused the exception. After the user clicks 'Ok', the program continues to run properly.

Visual C++ (as well as other development tools from Microsoft) doesn't provide an automatic exception handling module like Delphi, so if you want to avoid crashes in your C/C++ application, you have to explicitly add exception handling routines to your software.

Read more: Codeproject

Posted via email from jasper22's posterous

0 comments: