![]() |
.NET database and distributed computing tools |
BFC | Visual Studio | Database Technology | Distributed Computing | Utility Classes
Advanced Error Handling
|
|
During AbandonShip processing all database connections are closed, as are open files (through special processing in clsFile, a Utility library class found in B1UCFil.h & cpp). No attempt is made to cleanup memory that has been dynamically allocated by the user, such as strings and database record buffers, because memory leaks during abnormal termination are a relatively benign side-effect. Neither is any attempt made to give the end user one last chance to finish the current operation, which may have built-in logical traps. The application programmer is always free to Try/Catch errors and do any special handling desired instead of terminating the application. However, since for normal processing BFC functions always return completion codes instead of throwing errors, programmers usually find few instances where they feel compelled to code Try/Catch blocks. To put out a different AbandonShip dialog, for example, with a more detailed, user-friendly message, it's simplest to allow AbandonShip processing to take place and override the final display step. You can override the DispAbandonShip() function to display a custom tailored dlgAbandonShip. This allows you to cause, during abnormal termination, an application specific dialog box to come up whose contents is appropriate for the particular error. The AbandonShip dialog has been designed to make it convenient to provide an error report that is sufficiently detailed to be useful. A user can take a screen snapshot of it and then drag it aside and take another screen shot of the application as it looked right before the error. (These screen snapshots can be pasted into MS Word, for example, and then attached to an email report of the problem.) If the Error Hint in the Abandon Ship dialog is too long to be completely visible without scrolling (for example, a lengthy SQL statement that failed), the hint can also be separately highlighted, copied, and pasted into the problem report. The Utility library provides classes for handling return codes and associated exceptions, including:
In a typical BFC application, any Utility Exception class (clsUtilException) or other exception that is not handled is caught by the framework, the AbandonShip dialog is displayed, and the application is terminated cleanly. Putting a BREAKPOINT in the clsUtilException function gFn_ThrowUtilException() is especially helpful. You can then look at the call stack at exactly the point where the problem occurs. The Utility Exception class (clsUtilException) handles most but not all types of errors. For example, a third party library might throw and not handle a type of error not known to BFC. Fortunately, the BFC error handling mechanism catches it - but doesn't know what to do with it. You can override the default complaint of "unknown error" and process the exception yourself. Programmers can also make use of the same macros BFC employs for displaying Error File Name and Line Number during abnormal termination. Duplicate Data and Foreign Key Errors The error handling mechanism also provides additional useful information when some common data entry errors occur. Applications can obtain a comma separated list of the offending field(s) whenever duplicate data and foreign key errors are encountered. The offending constraint or index name is converted to the more understandable field name or list of field names responsible for the error. Normally the database error messages returned from back-ends are cryptic, such as "Unique constraint CONSTRAINT_XXX violated". Programs can obtain a field list and that information can be used to display more meaningful error messages to the user, and even put back the focus and highlight the offending field on the screen. Diagnostic FacilitiesBFC not only supports the tracing and debugging features of the Visual Studio development environment, but also we've added low-level facilities, such as database activity tracing, plus extra documentation to help you get the most out of Microsoft's programming tools. BFC goes a long way towards eliminating two major C++ bugaboos: memory leaks and memory overwrites. A BFC application built in Debug mode (as opposed to Release mode) automatically leverages MFC memory diagnostic facilities to detect these programmer errors. In addition, BFC adds a number of diagnostic capabilities that make debugging even easier:
Trace Facility (showing User Master screen & Oracle OCI calls) |
|
Five tracing options provide different levels of detail, and you can start and stop tracing at any point to collect just the information you need. If an error occurs and an AbandonShip (severe error) dialog is displayed, the trace window will be available at the same time as the dialog is displayed. The trace can be saved to a file at any point. The real strength in the Base/1 diagnostic facilities comes from BFC's general approach to error handling, which practically eliminates the need for the usual tracing and debugging tools. BFC classes for error handling and tracing have saved untold amounts of wasted debugging time, while improving the reliability and performance of applications in production. That is to say nothing of how glad programmers have been to avoid tedious, unrewarding hours of tracking down the causes of the same types of bugs and performance problems, over and over. |
BFC | Visual Studio | Database Technology | Distributed Computing | Utility Classes
|
|||||||
Home | Products | Consulting | Case Studies | Order | Contents | Contact | About Us |
|
|||||||
Copyright © 2012, Base One International Corporation |