exception_filter_006.phpt 942 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. --TEST--
  2. Test V8::setExceptionFilter() : re-throw exception in exception filter
  3. --SKIPIF--
  4. <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
  5. --FILE--
  6. <?php
  7. class myv8 extends V8Js
  8. {
  9. public function throwException(string $message) {
  10. throw new Exception($message);
  11. }
  12. }
  13. $v8 = new myv8();
  14. $v8->setExceptionFilter(function (Throwable $ex) {
  15. // re-throw exception so it is not forwarded
  16. throw $ex;
  17. });
  18. try {
  19. $v8->executeString('
  20. try {
  21. PHP.throwException("Oops");
  22. print("done\\n");
  23. }
  24. catch (e) {
  25. print("caught\\n");
  26. var_dump(e);
  27. }
  28. ', null, V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS);
  29. } catch (Exception $ex) {
  30. echo "caught in php: " . $ex->getMessage() . PHP_EOL;
  31. }
  32. ?>
  33. ===EOF===
  34. --EXPECT--
  35. caught in php: Oops
  36. ===EOF===