Although Catch ex As Exception
claims that it can handle all exceptions - there are one exception (no pun intended).
Imports System
Static Sub StackOverflow() ' Again no pun intended
StackOverflow()
End Sub
Static Sub Main()
Try
StackOverflow()
Catch ex As Exception
Console.WriteLine("Exception caught!")
Finally
Console.WriteLine("Finally block")
End Try
End Sub
Oops... There is an un-caught System.StackOverflowException
while the console didn't even print out anything! According to MSDN,
Starting with the .NET Framework 2.0, you can’t catch a StackOverflowException object with a try/catch block, and the corresponding process is terminated by default. Consequently, you should write your code to detect and prevent a stack overflow.
So, System.StackOverflowException
is un-catchable. Beware of that!