I am reading Jeffrey Richter's book "Applied Microsoft .NET Framework
programming",i came across "Exception handing". Page 405 says
"If the stack overflow occurs within the CLR itself,your application code
won't be able to catch the StackOverflowEx ception exception and none of your
finally blocks will excute.",I don't understand it.
Following C# statement:
class App
{
static void Main()
{
try
{
Console.WriteLi ne("This process will throw a StackOverflowEx ception");
ThrowStack();
}
catch (Exception ex)
{
Console.WriteLi ne(ex.Message);
}
finally
{
Console.WriteLi ne("Finally block execute");
Console.ReadLin e();
}
}
static void ThrowStack()
{
try
{
throw new StackOverflowEx ception("StackO verflowExceptio n is be throw by
user");
}
catch (StackOverflowE xception ex)
{
throw ex;
}
}
}
output:
This process will throw a StackOverflowEx ception
StackOverflowEx ception is be throw by user
Finally block execute
It seems catch block catch this exception and finally black execute,why?
Thanks for your help
programming",i came across "Exception handing". Page 405 says
"If the stack overflow occurs within the CLR itself,your application code
won't be able to catch the StackOverflowEx ception exception and none of your
finally blocks will excute.",I don't understand it.
Following C# statement:
class App
{
static void Main()
{
try
{
Console.WriteLi ne("This process will throw a StackOverflowEx ception");
ThrowStack();
}
catch (Exception ex)
{
Console.WriteLi ne(ex.Message);
}
finally
{
Console.WriteLi ne("Finally block execute");
Console.ReadLin e();
}
}
static void ThrowStack()
{
try
{
throw new StackOverflowEx ception("StackO verflowExceptio n is be throw by
user");
}
catch (StackOverflowE xception ex)
{
throw ex;
}
}
}
output:
This process will throw a StackOverflowEx ception
StackOverflowEx ception is be throw by user
Finally block execute
It seems catch block catch this exception and finally black execute,why?
Thanks for your help
Comment