What Exceptions bypass catch blocks in .net [duplicate] - c#

This question already has answers here:
What kind of Exceptions cannot be handled? [duplicate]
(2 answers)
Closed 8 years ago.
So from http://msdn.microsoft.com/en-us/library/ms173161.aspx
Once an exception is thrown, it propagates up the call stack until a catch statement for the exception is found.
So the implcation is that all exception typess can be either caught by a catch(ExceptionType) or a generic catch.
However this is plainly not true. For example AccessViolationException bypasses standard exception handling
How to handle AccessViolationException
So what other exceptions also bypass standard exception handling?

I would say that a StackOverflowException is most likely unhandled, I'm not aware of others.

Related

What happens if an exception is thrown during stack unwinding? [duplicate]

This question already has answers here:
What happens if an exception occurs in Catch block in C#. Also what would be the caller result in that case
(7 answers)
What happens if a finally block throws an exception?
(11 answers)
Closed 2 years ago.
When managed code is being executed by a .Net CLR, what happens if a second exception is thrown whilst the runtime is unwinding the stack due to an initial exception?
This doesn't refer to rethrowing an exception from a Catch block. It covers situations where an exception is thrown whilst the CLR is in the process of unwinding the stack.
In C++, this would cause the program to terminate, but I can't find any documentation about the behaviour in .Net.

Why Don't we Use General Exception Class (Exception) for Catching All Types Of Exceptions [duplicate]

This question already has answers here:
Is it really that bad to catch a general exception?
(15 answers)
Closed 4 years ago.
Why do we use the more specific exceptions like IndexOutOfRangeException
and DivideByZero exceptions when we can catch them in a catch block like this:
try
{
//Some Work
}
catch(Exception E){}
You should only ever write specific code to handle exceptions that you reasonably expect to be thrown. If you understand that specific code could throw a specific type of exception then you can determine exactly what to do in that situation. If you catch absolutely any type of exception then you will have no idea what the cause was and thus you can't know what should be done about it.

Correct try-catch syntax? [duplicate]

This question already has answers here:
Why catch and rethrow an exception in C#?
(17 answers)
Closed 8 years ago.
If I want to preserve the stack trace and I have this catch block...
try
{
//Cause exception here...
}
catch (CustomException customEx)
{
//Handle custom exception here...
}
catch
{
throw;
}
Will the above catch (without parameter) rethrow the exception?
Your question is unclear. Your actual question seems to be "Does a catch(SpecificException) fall through to the general catch?", to which the answer is "no".
If by "the" exception you mean "any other exception than CustomException", then yes, they will be rethrown.
If you want to rethrow the latter too, you'll also need a throw in the catch(CustomException customex).
you can use try-catch-finally
A common usage of catch and finally together is to obtain and use resources in a try block, deal with exceptional circumstances in a catch block, and release the resources in the finally block.
For more information and examples on re-throwing exceptions, see try-catch and Throwing Exceptions. For more information about the finally block, see try-finally.
for more details see
https://msdn.microsoft.com/en-us/library/dszsf989.aspx

Check all exceptions that a piece of code can throw [duplicate]

This question already has answers here:
How can I determine which exceptions can be thrown by a given method?
(9 answers)
Finding out what exceptions a method might throw in C#
(4 answers)
Closed 9 years ago.
Very simple really - is there a way to check and make a list of all exceptions that a method might throw? I have used try/catch but I want to make sure I didn't miss anything, and going through big files line by line to check if that line is throwing something that might be uncaught on runtime is a pain...
Oh yeah, I am using C#, .NET 4.5 and VS2012 PRO.
Thanks good people.
In C#, all objects that are thrown must derive from System.Exception. If you catch System.Exception, you catch them all, no matter what subtype.

Catching First Chance Exceptions in Managed Code without being debugged [duplicate]

This question already has answers here:
Is there a way to log or intercept First Chance Exceptions
(3 answers)
Closed 5 years ago.
Is there a way to catch First-Chance exceptions, and log them without running under a debugger?
I suppose another way to ask the question is can I write something that will act like a debugger being attached to my process and see what is going wrong while it happens?
If you are on .NET 4.0, you can use theAppDomain.FirstChanceExceptionevent to get notification of exceptions.

Categories