O'Reilly logo

Applied Microsoft® .NET Framework Programming by Jeffrey Richter

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Catch Filters

When an exception is thrown, the CLR walks up the call stack looking at each catch block’s catch filter—the exception type in a catch block’s parentheses. The following code shows a try block with three catch blocks.

public void SomeMethod() {
   try {
      // Do something in here.
   }
   catch (NullReferenceException e) {
      // Handle a null reference exception.
   }
   catch (InvalidCastException e) {
      // Handle an Invalid cast exception.
   }
   catch {  // In C#, this filter catches everything.
      // Handle any kind of exception.
   }
}

When compiling this code, the compiler emits a tiny "catch filter funclet" for each catch block contained inside the SomeMethod method. When an exception is thrown, the CLR calls the NullReferenceException funclet and passes it the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required