Add missing scope::operator=.
[luabind.git] / src / exception_handler.cpp
blob555d3858ca96bca8fa4d93928d7b697f39688c77
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>
10 #include <stdexcept>
12 #ifndef LUABIND_NO_EXCEPTIONS
14 namespace luabind { namespace detail {
16 namespace
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, "'");
26 lua_concat(L, 4);
30 void exception_handler_base::try_next(lua_State* L) const
32 if (next)
33 next->handle(L);
34 else
35 throw;
38 LUABIND_API void handle_exception_aux(lua_State* L)
40 try
42 if (handler_chain)
43 handler_chain->handle(L);
44 else
45 throw;
47 catch (error const&)
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);
65 catch (...)
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;
74 else
76 exception_handler_base* p = handler_chain;
78 for (; p->next; p = p->next);
80 handler->next = 0;
81 p->next = handler;
85 }} // namespace luabind::detail
87 #endif // LUABIND_NO_EXCEPTIONS