Re: Handling unhandled exceptions



"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.


.



Relevant Pages

  • RE: Handling unhandled exceptions
    ... The community members have provided good replies to you now. ... Just as Jeroen pointed out, as a library, your responsibility is throwing ... the exception for bad condition. ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.languages.vc)
  • RE: Can I throw an exception from my managed callback?
    ... My managed callback threw an exception, ... and yet the return from ProcessTrace() was SUCCESS. ... Microsoft Online Community Support ... You can send feedback directly to my manager at: ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Step by Step skips large chunks of code
    ... I have several applications that are threaded and I use exception handling ... The debugger product team has already identified the root cause of this ... Microsoft Online Community Support ... You can send feedback directly to my manager at: ...
    (microsoft.public.vsnet.debugging)
  • RE: Exception on SQLDependency background thread
    ... Microsoft MSDN Online Support Lead ... You can send feedback directly to my manager at: ... nature are best handled working with a dedicated Microsoft Support Engineer ... been crashing and not going through any of my exception management code. ...
    (microsoft.public.dotnet.framework.adonet)
  • RE: Can I throw an exception from my managed callback?
    ... ProcessTrace API return corresponding error code, when managed callback ... function throws an exception. ... Microsoft Online Community Support ... You can send feedback directly to my manager at: ...
    (microsoft.public.dotnet.framework.interop)