1 // Copyright Daniel Wallin 2005. Use, modification and distribution is
2 // subject to the Boost Software License, Version 1.0. (See accompanying
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 #include <luabind/config.hpp>
8 #include <luabind/exception_handler.hpp>
9 #include <luabind/error.hpp>
12 namespace luabind
{ namespace detail
{
16 exception_handler_base
* handler_chain
= 0;
18 void push_exception_string(lua_State
* L
, char const* exception
, char const* what
)
20 lua_pushstring(L
, exception
);
21 lua_pushstring(L
, ": '");
22 lua_pushstring(L
, what
);
23 lua_pushstring(L
, "'");
28 void exception_handler_base::try_next(lua_State
* L
) const
36 LUABIND_API
void handle_exception_aux(lua_State
* L
)
41 handler_chain
->handle(L
);
47 catch (std::logic_error
const& e
)
49 push_exception_string(L
, "std::logic_error", e
.what());
51 catch (std::runtime_error
const& e
)
53 push_exception_string(L
, "std::runtime_error", e
.what());
55 catch (std::exception
const& e
)
57 push_exception_string(L
, "std::exception", e
.what());
59 catch (char const* str
)
61 push_exception_string(L
, "c-string", str
);
65 lua_pushstring(L
, "Unknown C++ exception");
69 LUABIND_API
void register_exception_handler(exception_handler_base
* handler
)
71 if (!handler_chain
) handler_chain
= handler
;
74 exception_handler_base
* p
= handler_chain
;
76 for (; p
->next
; p
= p
->next
);
83 }} // namespace luabind::detail