Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception handler

There is this code:

char text[] = "zim";
int x = 777;

If I look on stack where x and text are placed there output is:

09 03 00 00 7a 69 6d 00

Where:

  • 09 03 00 00 = 0x309 = 777 <- int x = 777
  • 7a 69 6d 00 = char text[] = "zim" (ASCII code)

There is now code with try..catch:

char text[] = "zim";
try{
  int x = 777;
}
catch(int){
}

Stack:

09 03 00 00 **97 85 04 08** 7a 69 6d 00

Now between text and x is placed new 4 byte value. If I add another catch, then there will be something like:

09 03 00 00 **97 85 04 08** **xx xx xx xx** 7a 69 6d 00

and so on. I think that this is some value connected with exception handling and it is used during stack unwinding to find appropriate catch when exception is thrown in try block. However question is, what is exactly this 4-byte value (maybe some address to excception handler structure or some id)?

I use g++ 4.6 on 32 bit Linux machine.

like image 439
scdmb Avatar asked Feb 12 '12 16:02

scdmb


People also ask

What does an exception handler do?

An exception handler is code that stipulates what a program will do when an anomalous event disrupts the normal flow of that program's instructions. An exception, in a computer context, is an unplanned event that occurs while a program is executing and disrupts the flow of its instructions.

What are exception handlers in Java?

Java Exception Handling is a mechanism to handle runtime errors such as ClassNotFoundException, IOException, SQLException, RemoteException, etc. Exception is an unwanted or unexpected event, which occurs during the execution of a program, i.e. at run time, that disrupts the normal flow of the program's instructions.

What is example of exception handling?

Example: Exception handling using try... In the example, we are trying to divide a number by 0 . Here, this code generates an exception. To handle the exception, we have put the code, 5 / 0 inside the try block. Now when an exception occurs, the rest of the code inside the try block is skipped.

What is an exception handler C++?

Exception handling is a mechanism that separates code that detects and handles exceptional circumstances from the rest of your program. Note that an exceptional circumstance is not necessarily an error. When a function detects an exceptional situation, you represent this with an object.


1 Answers

AFAICT, that's a pointer to an "unwind table". Per the the Itanium ABI implementation suggestions, the process "[uses] an unwind table, [to] find information on how to handle exceptions that occur at that PC, and in particular, get the address of the personality routine for that address range. "

The idea behind unwind tables is that the data needed for stack unwinding is rarely used. Therefore, it's more efficient to put a pointer on the stack, and store the reast of the data in another page. In the best cases, that page can remain on disk and doesn't even need to be loaded in RAM. In comparison, C style error handling often ends up in the L1 cache because it's all inline.

like image 69
MSalters Avatar answered Nov 16 '22 03:11

MSalters