Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are try/catch blocks implemented?

If an exception occurs in a try block, how is execution transferred to the catch block? This is not a C#/Java/C++ question, I'm just wondering how it works internally.

like image 780
selvaraj Avatar asked Sep 27 '10 09:09

selvaraj


2 Answers

this is not a c#/java/c++ question. How it works internally,how the line knows to go catch statement.

How this works internally makes this pretty much a c#/java/C++ question (because it will be implemented differently).

In Java, a try block installs itself into a special table (in the class file). When the JVM throws an exception, it looks at that table to see where the next catch or finally block to go to is.

like image 85
Thilo Avatar answered Oct 13 '22 18:10

Thilo


When an exception occurs a special instruction is executed (usually called interrupt). This leads to executing a generic error handler that deduces which is the latest installed suitable exception handler. That handler is then executed.

like image 20
sharptooth Avatar answered Oct 13 '22 18:10

sharptooth