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)
5 #define LUABIND_BUILDING
7 #include <luabind/config.hpp>
8 #include <luabind/exception_handler.hpp>
9 #include <luabind/error.hpp>
12 #ifndef LUABIND_NO_EXCEPTIONS
14 namespace luabind
{ namespace detail
{
18 exception_handler_base
* handler_chain
= 0;
20 void push_exception_string(lua_State
* L
, char const* exception
, char const* what
)
22 lua_pushstring(L
, exception
);
23 lua_pushstring(L
, ": '");
24 lua_pushstring(L
, what
);
25 lua_pushstring(L
, "'");
30 void exception_handler_base::try_next(lua_State
* L
) const
38 LUABIND_API
void handle_exception_aux(lua_State
* L
)
43 handler_chain
->handle(L
);
49 catch (std::logic_error
const& e
)
51 push_exception_string(L
, "std::logic_error", e
.what());
53 catch (std::runtime_error
const& e
)
55 push_exception_string(L
, "std::runtime_error", e
.what());
57 catch (std::exception
const& e
)
59 push_exception_string(L
, "std::exception", e
.what());
61 catch (char const* str
)
63 push_exception_string(L
, "c-string", str
);
67 lua_pushstring(L
, "Unknown C++ exception");
71 LUABIND_API
void register_exception_handler(exception_handler_base
* handler
)
73 if (!handler_chain
) handler_chain
= handler
;
76 exception_handler_base
* p
= handler_chain
;
78 for (; p
->next
; p
= p
->next
);
85 }} // namespace luabind::detail
87 #endif // LUABIND_NO_EXCEPTIONS