/hphp/test/slow/ir_inlining/try_catch_call_001.php
PHP | 43 lines | 34 code | 6 blank | 3 comment | 11 complexity | 7c3314e69379ad9c01589cde9d3bd9ae MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
- <?hh
- function thrower() {
- for ($i = 0; $i < 10; ++$i) mt_rand(); // make it not-inlinable
- // Make hhbbc not prove it's going to throw:
- for ($i = 0; $i < 10 + mt_rand() ? 1 : 0; ++$i) {
- mt_rand();
- }
- if ($i >= 10) throw new Exception('heh');
- return false;
- }
- function better_handle_exceptions_if_you_inline() {
- try {
- thrower();
- } catch (Exception $x) {
- echo "got it\n";
- return "all is well";
- }
- }
- function main() {
- // Generate a prologue for thrower:
- try { thrower(); } catch (Exception $x) {}
- // Push down bytecode offsets
- for ($i = 0; $i < 10; ++$i) mt_rand();
- for ($i = 0; $i < 10; ++$i) mt_rand();
- for ($i = 0; $i < 10; ++$i) mt_rand();
- for ($i = 0; $i < 10; ++$i) mt_rand();
- for ($i = 0; $i < 10; ++$i) mt_rand();
- for ($i = 0; $i < 10; ++$i) mt_rand();
- for ($i = 0; $i < 10; ++$i) mt_rand();
- for ($i = 0; $i < 10; ++$i) mt_rand();
- $z = better_handle_exceptions_if_you_inline();
- var_dump($z);
- }
- <<__EntryPoint>>
- function main_try_catch_call_001() {
- main();
- }