Optimize struct element initialization
[hiphop-php.git] / hphp / runtime / vm / unwind-inl.h
blobea0e5b8db105263dfb7e69ebfe781bf7a001f1e4
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_VM_UNWIND_INL_H_
18 #error "unwind-inl.h should only be included by unwind.h"
19 #endif
21 namespace HPHP {
22 ///////////////////////////////////////////////////////////////////////////////
24 template<class Action>
25 inline bool exception_handler(Action action) {
26 Trace::Indent _i;
27 try {
28 action();
29 return true;
32 catch (const Object& o) {
33 checkVMRegState();
34 ITRACE_MOD(Trace::unwind, 1, "unwind: Object of class {}\n",
35 o->getVMClass()->name()->data());
36 assertx(o.get());
37 if (vmfp() == nullptr) throw;
38 unwindVM(o.get());
39 return false;
42 catch (Exception& e) {
43 checkVMRegState();
44 ITRACE_MOD(Trace::unwind, 1, "unwind: Exception: {}\n", e.what());
45 if (vmfp() == nullptr) throw;
46 unwindVM(e.clone());
47 not_reached();
50 catch (std::exception& e) {
51 checkVMRegState();
52 ITRACE_MOD(Trace::unwind, 1, "unwind: std::exception: {}\n", e.what());
53 auto const exn =
54 new Exception("unexpected %s: %s", typeid(e).name(), e.what());
55 if (vmfp() == nullptr) exn->throwException();
56 unwindVM(exn);
57 not_reached();
60 catch (CppDummyException& e) {
61 always_assert_flog(false,
62 "CppDummyException should not reach exception_handler");
65 catch (...) {
66 checkVMRegState();
67 ITRACE_MOD(Trace::unwind, 1, "unwind: unknown\n");
68 auto const exn = new Exception("unknown exception");
69 if (vmfp() == nullptr) exn->throwException();
70 unwindVM(exn);
71 not_reached();
75 ///////////////////////////////////////////////////////////////////////////////