Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the right approach when no handler is found in the call stack in C# program

Tags:

c#

.net

exception

I ask this question because soon I'll have interview heavily focused on error handling but also this is something I haven't figure out even though I have almost 7 months as a junior C# developer.

As the title says I want to know what is the right way to deal with exceptions form which there is no appropriate error handler. Some time ago I've heard a colleague of mine talking about generic exception handler (whatever that may mean) which is responsible to deal with suck case scenarios. However I did I little googling I haven't been able to find some information about such a thing.

So my question is - how to deal with those kind of exceptions and my subquestion is - is there really something called generic exception handler?

like image 312
Leron_says_get_back_Monica Avatar asked Mar 22 '23 08:03

Leron_says_get_back_Monica


1 Answers

is there really something called generic exception handler?

Yes - that's what they call the handler that logs the exception and stores as much info as possible before quitting the program. One way to set up a handler like that is adding a handler to the UnhandledException event of your AppDomain object.

It is neither "generic" nor a "handler" in the .NET sense, because no generic types are involved, and because the actions the handler could take are rather limited. Unlike a real handler which could block or re-throw the exceptions that it handles, the last-chance "handler" could see what's been thrown, but cannot cause the execution to continue.

like image 186
Sergey Kalinichenko Avatar answered Mar 24 '23 22:03

Sergey Kalinichenko