Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle unhandled exceptions only from certain assemblies

Well, maybe a odd question, but how would I handle unhandled exceptions only from certain assemblies in a application, but including exceptions that originate from .NET itself, like for instance when you get a ADO.NET exception it originates from .NET assembly.

I need this because of working with the legacy application where I need unhandled exception handling only for a module consisting of several assemblies, and everything is in the same application in the end, as a part of same process.

Can I maybe catch exceptions on assembly level, instead on the global Application level ?

like image 306
Denis Biondic Avatar asked Jun 12 '26 16:06

Denis Biondic


1 Answers

Just check the stack trace and use throw; if you should not handle the exception.

try
{
    //something
}
catch (Exception err)
{
    if (!err.StackTrace.Contains("YourAssemblyName"))
        throw;
}
like image 194
jgauffin Avatar answered Jun 14 '26 04:06

jgauffin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!