
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Preventing Unhandled Exceptions
|
391
Discussion
Handle any user-defined exceptions that are unique to a specific COM/COM+ com-
ponent by trapping the
COMException exception. This class reflects COM/COM+
HRESULTs that have no mapping to managed exceptions.
The
COMException has a property, ErrorCode, in addition to those properties in the
base
Exception class. This property contains the HRESULT value that the COM/COM+
object returned. Another difference between
COMException and Exception is that the
InnerException property of a COMException object will always be null.
See Also
See the “Error Raising and Handling Guidelines” and “Handling COM Interop
Exceptions” topics in the MSDN documentation.
7.10 Preventing Unhandled Exceptions
Problem
You need to make absolutely sure that every exception thrown by your application is
handled and that no exception is bubbled up past the outermost exception handler.
Hackers often use these types of exceptions to aid in their analysis of the vulnerabili-
ties of a web application for instance.
Solution
Place try-catch or try-catch-finally blocks in strategic places in your application.
In addition, use the exception event handler as a final line of defense against unhan-
dled exceptions.
Discussion
If an exception occurs and is not handled, it will cause your application ...