[PHP] Re-raise exception #57

Open
hbarcelos opened this Issue Jun 15, 2016 · 0 comments

Projects

None yet

1 participant

@hbarcelos

I noticed the re-raise exception section is empty.

In this case, PHP is exatcly like Javascript/Node:

try {
  throw new Exception("bam!");
} catch (Exception $e) {
  trigger_error("Re-throw", E_USER_WARNING);
  throw $e;
}

It's also possible to chain exceptions as of PHP 5.3:

try {
  throw new Exception("Bam!");
} catch (Exception $first) {
  throw new Exception("Another!", null, $first);
}

In this case, the output would be:

Uncaught exception 'Exception' with message 'Bam!' in /run_dir/repl.php(68) : eval()'d code:2
Stack trace:
#0 /run_dir/repl.php(68): eval()
#1 {main}

Next exception 'Exception' with message 'Another!' in /run_dir/repl.php(68) : eval()'d code:4
Stack trace:
#0 /run_dir/repl.php(68): eval()
#1 {main}
  thrown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment