none
How can I view all exceptions in our app? RRS feed

Answers

  • http://msdn.microsoft.com/en-us/library/dd997368(v=vs.110).aspx

    This event applies to AppDomain so should be able to catch those 3rd party libraries loaded. Mind you, the handler may not give you any useful information unless corresponding debug information is available.

    And as Magnus said, you shouldn't have thought on meddling with exceptions that has already been handled by the 3rd party library itself.

    • Marked as answer by DavidThi808 Tuesday, November 4, 2014 12:21 PM
    Tuesday, November 4, 2014 1:22 AM
    Answerer

All replies

  • If you pass all your exceptions to centralized logger, and set unhandled exception handler to the logger as well in your application, you should be able to catch all "exceptions" (There are OS level errors that don't pass to exception handler at all, like the "device not ready" one for CD drives)
    Monday, November 3, 2014 2:20 AM
    Answerer
  • Hi;

    How can I see them if I don't catch them all? We have lots of Windows message handlers that we don't catch because there's nothing for us to do on them, but we want to know about them.

    thanks - dave


    What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing

    Monday, November 3, 2014 11:47 AM
  • >>How can I see them if I don't catch them all?

    You can't. If you want to log an exception within your application your must catch them somewhere. Where do this depends on which kind of application you are developing but you can generally put a try..catch block around the first call in the entry point of the program.


    In a WPF application you can for example trap exceptions at different levels: http://stackoverflow.com/questions/1472498/wpf-global-exception-handler

    In Windows Forms you could hook up an event handler to the Application.ThreadException event: http://stackoverflow.com/questions/6291933/catch-application-exceptions-in-a-windows-forms-application

    Please remember to mark helpful posts as answer and/or helpful.

    Monday, November 3, 2014 12:08 PM
  • Hi;

    Yes, unfortunately those don't track handled non-UI exceptions. How can I do that? There must be a way because debuggers can break on handled exceptions.

    ??? - thanks - dave


    What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing

    Monday, November 3, 2014 2:05 PM
  • >>Yes, unfortunately those don't track handled non-UI exceptions

    No they don't and that's simply because already handled exceptions are just that handled. An exception that you handle yourself will not cause any of the mentioned events to be raised. This is the whole purpose of catching an exception in the first place.

    >>How can I do that?

    If you wish to log a handled exception you should do the logging or whatever in the catch block in your code:

    catch (Exception ex)
    {
       Logger.YourLogMethod(ex);
    }

    If you want to propagate an already handled exception, you should throw again:

    catch (Exception ex)
    {
       Logger.YourLogMethod(ex);
       throw;
    }

    The thing is that you should centralize your logging logic in a singel method or class and call this method whenever an exception occurs, either in a catch handler in your code or in a general catch handler somewhere else.

    There is no catch all handler that catches handles exceptions too if that's what you are looking for. The debugger can break execution of your application immediately when an exception occurs but that's simply a matter of breaking as soon as an exception is thrown and before it has been handled by the catch-block. After the catch-block there is no way to catch the already thrown and handled exception.

    Please remember to mark helpful posts as answer and/or helpful.

    Monday, November 3, 2014 2:20 PM
  • We're trying to track this in a 3rd party library that is not ours. So adding logging for each exception, while a great approach in most cases, won't work here.

    How can we do like a debugger and get called when an exception is about to be thrown?

    thanks - dave


    What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing

    Monday, November 3, 2014 3:30 PM
  • Once again: you cannot. The Visual Studio debugger is a separate process that is being attached to the application when running it in debug mode in Visual Studio.

    You cannot control what happens inside a third-party assembly from your code and you cannot catch any exceptions that are handled in there. Why would you want to do this anyway? I am afraid that it doesn't make much sense.

    You should ignore any kind of errors that are already being handled by third-party software or .NET and concentrate on fixing and logging your one ones.

    Monday, November 3, 2014 4:02 PM
  • http://msdn.microsoft.com/en-us/library/dd997368(v=vs.110).aspx

    This event applies to AppDomain so should be able to catch those 3rd party libraries loaded. Mind you, the handler may not give you any useful information unless corresponding debug information is available.

    And as Magnus said, you shouldn't have thought on meddling with exceptions that has already been handled by the 3rd party library itself.

    • Marked as answer by DavidThi808 Tuesday, November 4, 2014 12:21 PM
    Tuesday, November 4, 2014 1:22 AM
    Answerer
  • Yes - thank you!

    Also, we won't do anything with them, we just need to see what is happening.


    What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing

    Tuesday, November 4, 2014 12:21 PM