Last active
January 1, 2016 23:59
-
-
Save antonijn/8219885 to your computer and use it in GitHub Desktop.
How exception handling works.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static void f() | |
| { | |
| ThreadExEnv env = Thread.current().getExEnv(); | |
| void() fin = void () -> | |
| { | |
| // finally block | |
| // ... | |
| }; | |
| if (!env.registerHandler(fin)) | |
| { | |
| // try block | |
| // ... | |
| env.leave(); | |
| } | |
| else | |
| { | |
| Exception e = env.getEx(); | |
| Type t = e.getType(); | |
| if (t.subTypeOf(typeof(NullPtrException))) | |
| { | |
| NullPtrException npe = Object.forceCast<NullPtrException>(e); | |
| // catch (NullPtrException npe) block | |
| // ... | |
| env.leave(); | |
| } | |
| else if (t.subTypeOf(typeof(IOException))) | |
| { | |
| IOException ioe = Object.forceCast<IOException>(e); | |
| // catch (IOException ioe) block | |
| // ... | |
| env.leave(); | |
| } | |
| else | |
| { | |
| env.fallThrough(); | |
| } | |
| } | |
| } | |
| private static void g(Exception e) | |
| { | |
| Thread.current().getExEnv().raise(e); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static void f() | |
| { | |
| try | |
| { | |
| // try block | |
| // ... | |
| } | |
| catch (NullPtrException npe) | |
| { | |
| // catch (NullPtrException npe) block | |
| // ... | |
| } | |
| catch (IOException ioe) | |
| { | |
| // catch (IOException ioe) block | |
| // ... | |
| } | |
| finally | |
| { | |
| // finally block | |
| // ... | |
| } | |
| } | |
| private static void g(Exception e) | |
| { | |
| throw e; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment