Preventing application crash by using exception handling mechanism
来源:互联网 发布:js中有返回值的函数 编辑:程序博客网 时间:2024/06/05 05:42
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.
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.
The ExceptionTest Example
The ExceptionTest project example demonstrate how to avoid application crash, by using the __try and __except statements. When you run the sample, you get a dialog-box containing 2 buttons that deliberately causes an exception. The first button raises the exception without exception handling block, and this causes the application to crash immediately. The second button raises the exception from within a __try block. When the exception is occurred, the function inside the __except statement (GetExceptionInformation) is called. This function displays a special dialog-box with a little information about the exception, and allow the user to decide whether he wants to continue to run the program or to terminate it. The user can also copy the exception information to the clipboard in order to send it to the author of the software.
Download ExceptionTest Sample (For running in Visual C++ 6.0)
- Preventing application crash by using exception handling mechanism
- JAVA fundamentals of exception handling mechanism
- Exception Handling using Enterprise Library
- Logging & Exception Handling Application Block
- Exception Handling and Crash Reporting - Part 1
- Exception Handling in WCF using Fault Contract
- Centralised Exception Handling in C# Windows Application
- Exception Handling Application Block (5)详细解
- Manage Exception Handling in Spring Application
- XCrashReport : Exception Handling and Crash Reporting - Part 1
- XCrashReport : Exception Handling and Crash Reporting - Part 1
- Enterprise Library: Exception Handling Application Block类设计分析
- Enterprise Library Exception Handling Application Block 学习笔记 - 1
- Enterprise Library Exception Handling Application Block 学习笔记 - 2
- Enterprise Library Exception Handling Application Block 学习笔记 - 3
- Microsoft Enterprise Library 5.0 系列(七) Exception Handling Application Block
- Microsoft Enterprise Library 5.0 系列(七) Exception Handling Application Block
- Exception handling
- 对linux中SUID标志位的理解
- XML与DataSet的相互转换的类
- 用C#创建Windows服务(Windows Services)
- Moving items up and down in a ListView control
- Displaying 'Browse Folders' dialog with the default folder selected
- Preventing application crash by using exception handling mechanism
- 李开复:21世纪最需要的7种人才
- Enumerating Windows credentials with CredEnumerate function (Windows XP/2003 Only)
- 创建DataTable对象(ADO.NET)
- Email地址加密一例
- Displaying the 'Properties' of a file or folder.
- 纪念“5.12”特大 土也 震!!!
- 主流RIA技术的简单比较:来自JavaFX、Flex和Silverlight的问候(三)
- @@identity的作用是返回最后插入的标识值