Re: Handling unhandled exceptions
- From: "Ben Voigt [C++ MVP]" <rbv@xxxxxxxxxxxxx>
- Date: Fri, 7 Mar 2008 08:38:34 -0600
"Jeffrey Tan[MSFT]" wrote:
Hi Bob,
Jeffrey,
I believe you missed the statement "It exposes native C-style entry points,
calls into the managed library, and marshals the results (if any) back to
the native caller." because all your advice is inapplicable to the case of a
native caller.
The community members have provided good replies to you now. I wanted
to add some comment:
Just as Jeroen pointed out, as a library, your responsibility is
throwing the exception for bad condition. It is the application
developer's responsibility to set a top-level unhandled exception
handler to report all the information. If they did not do that, it is
their problem. Your responsibility is documenting all the possible or
expected exceptions for easy methods/routines in your library
documents like what MSDN does.
Furthermore, I do not recommend you to use try...catch clause around
all the methods/routines, because this will eliminate the caller's
chance to fix the exception. For example, if one method is openning
certain file and the caller supplies a wrong path to your method. A
FileNotFoundException may be thrown from your method. The caller may
use a try...catch for this exception and notify the user with a
dialog to supply a legal file path. However, if you try...catch this
in your library and just kill the application, you did not give the
caller any chance to fix it.
Is your library used in .Net Winform application? .Net has different
approaches to handle unhandled exceptions for console, Winform and
Asp.net applications. Winform's main GUI thread will use
Application.ThreadException event to handle the exception. So, if your
library is tested in .Net Winform,
AppDomain.CurrentDomain.UnhandledException event will not catch it.
See the article for more details:
"Unexpected Errors in Managed Applications"
http://msdn2.microsoft.com/en-us/magazine/cc188720.aspx
Hope it helps.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments
and suggestions about how we can improve the support we provide to
you. Please feel free to let my manager know what you think of the
level of service provided. You can send feedback directly to my
manager at: msdnmg@xxxxxxxxxxxxxx
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues where an initial response from the community or a Microsoft
Support Engineer within 1 business day is acceptable. Please note
that each follow up response may take approximately 2 business days
as the support professional working with you may need further
investigation to reach the most efficient resolution. The offering is
not appropriate for situations that require urgent, real-time or
phone-based interactions or complex project analysis and dump
analysis issues. Issues of this nature are best handled working with
a dedicated Microsoft Support Engineer by contacting Microsoft
Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
.
- Follow-Ups:
- Re: Handling unhandled exceptions
- From: "Jeffrey Tan[MSFT]"
- Re: Handling unhandled exceptions
- References:
- Handling unhandled exceptions
- From: Bob Altman
- RE: Handling unhandled exceptions
- From: "Jeffrey Tan[MSFT]"
- Handling unhandled exceptions
- Prev by Date: RE: Handling unhandled exceptions
- Next by Date: Re: WinForms Textbox in MFC CDialogBar
- Previous by thread: RE: Handling unhandled exceptions
- Next by thread: Re: Handling unhandled exceptions
- Index(es):
Relevant Pages
|