1

I want whenever an exception happens during execution of a function to automatically call a function before go to catch like a logger. typically something like this:

{
    try
    {
        //some code
    }
    catch(Exception e)
    {
        //I want the below call to happen automatically instead of me writing it everytime
        someFunction(e);
    }
}
ATM
  • 71
  • 10
  • 2
    That's a very good and valid question, I don't understand the downvote you got. There are various points where you can attach a global exception handler. I have linked a duplicate question which describes the most common one (`AppDomain.CurrentDomain.UnhandledException`). There are other, more specific ones which depend on the UI framework that you use (ASP.NET, WPF, WinForms). The Google expression you are looking for is "c# global exception handler", extended by the UI technology you use. – Heinzi Nov 17 '20 at 09:58
  • There's a probable dupe here [How to log all thrown exceptions?](https://stackoverflow.com/questions/7076063/how-to-log-all-thrown-exceptions) – Cid Nov 17 '20 at 10:00
  • https://learn.microsoft.com/en-us/dotnet/api/system.appdomain.firstchanceexception?view=net-5.0 – Hans Passant Nov 17 '20 at 10:05
  • @Heinzi thanks a lot. this exactly what I am looking for. – ATM Nov 17 '20 at 10:11
  • https://learn.microsoft.com/en-us/aspnet/web-api/overview/error-handling/web-api-global-error-handling – ATM Nov 17 '20 at 10:27

0 Answers0