Re: Catching exceptions
Jason McKesson <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
On Apr 29, 2011 9:28 AM, Josh Klint wrote:
>
> I created a C++ function to throw an exception:
>
> void RuntimeError(const std::string& error)
>
> {
>
> throw std::exception(error.c_str());
>
> }
>
> Here is the Lua script that calls it:
>
> print("Creating an error...")
>
> RuntimeError("An error has occurred!")
>
> Here is the code that runs the script. Instead of catching the
> exception, lua_pcall returns non-zero and the Lua string at the top of
> the stack contains "std-exception: 'An error has occurred!'":
>
> bool Interpreter::Invoke(const int& in, const int& out)
>
> {
>
> try
>
> {
>
> if (lua_pcall(L,in,out,0)==0)
>
> {
>
> return true;
>
> }
>
> else
>
> {
>
> //If you throw an exception, it gets displayed here,
> which isn't what we want:
>
> HandleError();
>
> }
>
> }
>
> //Exceptions should be getting caught here:
>
> catch(luabind::error& e)
>
> {
>
> Print("Caught the exception!");
>
> exit(1);
>
> }
>
> return false;
>
> }
>
> I am using MSVC, and I know about the issue described below. The code
> they said to add has no effect on behavior:
>
> http://www.rasterbar.com/products/luabind/docs.html#structured-exceptions-msvc
>
> What do I have to do to make my program catch the exception thrown by
> the C++ function the Lua script calls? Thanks.
>
>
You have to use Luabind to call the script. If you use Lua functions to
execute the script, then there will be no Luabind in the way to catch
the exception and convert it.
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today. Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user