clarkgrubb / hyperpolyglot

hyperpolyglot.org
Other
479 stars 96 forks source link

[PHP] Re-raise exception #57

Open hbarcelos opened 8 years ago

hbarcelos commented 8 years ago

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