Skip to content

Instantly share code, notes, and snippets.

@antonijn
Last active January 1, 2016 23:59
Show Gist options
  • Select an option

  • Save antonijn/8219885 to your computer and use it in GitHub Desktop.

Select an option

Save antonijn/8219885 to your computer and use it in GitHub Desktop.
How exception handling works.
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);
}
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