test_exception2.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php {
  2. class Foo {
  3. private $v8 = NULL;
  4. public function __construct()
  5. {
  6. $this->v8 = new V8Js(null, array(), false);
  7. $this->v8->foo = $this;
  8. // $this->v8->executeString('asdasda< / sd', 'trycatch0');
  9. // $this->v8->executeString('blahnothere', 'trycatch1');
  10. // $this->v8->executeString('throw new SyntaxError();', 'throw');
  11. // $this->v8->executeString('function foo() {throw new SyntaxError();}', 'trycatch2');
  12. // $this->v8->executeString('try { foo(); } catch (e) { print(e + " catched by pure JS!\n"); }', 'trycatch3');
  13. // $this->v8->executeString('try { PHP.foo.bar(); } catch (e) { print(e + " catched via PHP callback!\n"); }', 'trycatch4');
  14. // $this->v8->executeString('try { PHP.foo.bar(); } catch (e) { print("catched!\n"); }', 'trycatch5');
  15. // $this->v8->executeString('try { PHP.foo.bar(); } catch (e) { print("catched!\n"); }', 'trycatch5');
  16. var_dump($this->v8->getPendingException());
  17. }
  18. public function bar()
  19. {
  20. // $this->v8->executeString('asdasda< / sd', 'trycatch0');
  21. // $this->v8->executeString('blahnothere', 'trycatch1');
  22. $this->v8->executeString('throw new Error();', 'throw');
  23. }
  24. }
  25. try {
  26. $foo = new Foo();
  27. } catch (V8JsException $e) {
  28. echo "PHP Exception: ", $e->getMessage(), "\n";
  29. }
  30. }