Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7073939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:59:25+00:00 2026-05-28T05:59:25+00:00

Catching Own First Chance Exceptions AppDomain.CurrentDomain.FirstChanceException += FirstChanceException; private static void FirstChanceException(object sender, System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs

  • 0

Catching Own First Chance Exceptions

AppDomain.CurrentDomain.FirstChanceException += FirstChanceException;

private static void FirstChanceException(object sender, System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs e)
    {
        // I would like to log exceptions happening outside my assembly?
        // But this event does not receive external FirstChanceExceptions
        // (unlike Visual Studio debug output)
        myLogger.Log(e.Exception);
    }

Example

  • I would like to log A first chance exception of type 'System.IO.IOException' occurred in WindowsBase.dll

  • But not log A first chance exception of type 'System.DivideByZeroException' occurred in MyApp.exe

Solution?

  • Is there a way to get notified of those exceptions arising in dlls such as mscorlib.dll?
  • Note the interest is to log in the production release, not only in debugging.

Why

Exceptions that occur in external dll dependencies can cause trouble, even if they are handled there.

For example, due to an exception a null value may be returned from an external method (instead of returning the desired output of x) and even though my code mostly handles such abnormal output it is useful to know what exactly went wrong and where – because while I may be able to avoid fatal exceptions then more often than not that null value makes part of my app non-functional. So logging the external first chance exception would provide valuable information to help rectify the issue / turn that null into x. And this may be present in only given environments / for specific users etc…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:59:26+00:00Added an answer on May 28, 2026 at 5:59 am

    You can use StackTrace class to check what is the source of the exception:

    var stackTrace = new StackTrace(e.Exception);
    var sourceFrame = stackTrace.GetFrame(0);
    var throwingMethod = sourceFrame.GetMethod();
    var sourceAssembly = throwingMethod.DeclaringType.Assembly;
    var assemblyName = sourceAssembly.GetName().Name;
    
    bool isMyApp = assemblyName == "MyApp";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried two ways of catching unexpected unhandled exceptions: static void Main() { AppDomain.CurrentDomain.UnhandledException
By referring to C++ catching all exceptions try { int i = 0; int
How does one go about catching exceptions from using controls in markup? For example,
I had someone mention to me that catching all exceptions is not necessarily good
What are the best practices to consider when catching exceptions and re-throwing them? I
I'm working on catching a seriously insidious bug that's happening in my code. The
I am catching keys for bindings, so far most characters work fine, until I
I have something here that is really catching me off guard. I have an
I have a problem in catching an exception. I am trying to rethrow an
I am using the exception catching procedure which is the module to track the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.