Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The internal implementation of exception handling

Today, when I write a piece of code like this:

try
{
   ...
}
catch (Exception e)
{
   ...
}

I suddenly realize that the

catch (Exception e)
{
  ...
}

statement is so much like a function declaration. And I vaguely remembered that the exception handling involves some kind of stack walking/manipulation.

So, what exactly is the above exception handling code compiled into? I have the feeling that the above code is just a special/convenient syntax to ease our coding, but in fact, maybe our code is wrapped into an auto-generated exception handling function? I hope I made myself clear.

like image 903
smwikipedia Avatar asked Apr 19 '11 16:04

smwikipedia


People also ask

How do you implement exception handling?

The try-catch is the simplest method of handling exceptions. Put the code you want to run in the try block, and any Java exceptions that the code throws are caught by one or more catch blocks. This method will catch any type of Java exceptions that get thrown. This is the simplest mechanism for handling exceptions.

What is process of exception handling?

Exception handling is the process of responding to unwanted or unexpected events when a computer program runs. Exception handling deals with these events to avoid the program or system crashing, and without this process, exceptions would disrupt the normal operation of a program.

How is exception handling implemented in object Oriented Programming?

In Object-Oriented Programming (OOP), exceptions are a powerful mechanism for centralized processing of errors and exceptional situations. This mechanism replaces the procedure-oriented method of error handling in which each function returns a code indicating an error or a successful execution.


1 Answers

Fortunately for you CLR architect Chris Brumme wrote a long explanation of how exception handling works in the CLR. Now, this was written eight years ago and a few of the details are slightly different today, but this should at least give you a good start.

http://blogs.msdn.com/b/cbrumme/archive/2003/10/01/51524.aspx

like image 141
Eric Lippert Avatar answered Nov 14 '22 00:11

Eric Lippert