Catching exceptions

"Josh Klint" <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <000001cc068a$7a191760$6e4b4620$@com>
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-ms
vc

 

What do I have to do to make my program catch the exception thrown by the
C++ function the Lua script calls?  Thanks.

------------------------------------------------------------------------------
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.