error exceptions

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

error exceptions

strattonbrazil
I'm trying to get error messages to display and I was following this
tutorial.  However, I can't seem to get any error exceptions.  In a
lua script I'm running, I have a print at the top and bottom and it's
only hitting the top one, so I'm assuming there is some error in there
I thought should raise an exception.

http://www.nuclex.org/articles/5-cxx/1-quick-introduction-to-luabind

void loadLuaFile(lua_State* state, QString fileName)
{
    QFile file(fileName);
    file.open(QIODevice::ReadOnly);
    QString lines = file.readAll();
    //std://:cout << lines.toStdString() << std::endl;
    try {
        std::cout << "executing " << fileName.toStdString() <<
"...\n-----------" << std::endl;
        std::cout << lines.toStdString().c_str() << std::endl;
        luaL_dostring(state, lines.toStdString().c_str());
    } catch (const std::exception &TheError) {
        std::cout << "*" << std::endl;
        std::cout << TheError.what() << std::endl;
    }

    file.close();
}

------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: error exceptions

Willi Schinmeyer
Am Dienstag, den 09.08.2011, 07:17 -0700 schrieb Josh Stratton:
> so I'm assuming there is some error in there
> I thought should raise an exception.

Nope, errors don't usually raise exceptions, they just change the return
value. Read the manual regarding luaL_dostring(), I don't know how to
check its success off the top of my head.


------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: error exceptions

liam mail


On 9 August 2011 15:43, Willi Schinmeyer <[hidden email]> wrote:
Am Dienstag, den 09.08.2011, 07:17 -0700 schrieb Josh Stratton:
> so I'm assuming there is some error in there
> I thought should raise an exception.

Nope, errors don't usually raise exceptions, they just change the return
value. Read the manual regarding luaL_dostring(), I don't know how to
check its success off the top of my head.


------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user

luaL_dostring [1] is really a macro which calls two functions in Lua 5.1, it simply calls luaL_loadstring [2] then lua_pcall [3] if there was not an error. The macro is an "logical or" of both function return values and therefore luaL_dostring as such "returns" a result, either it is 0 for success or 1 for error. Using luaL_dostring looses information of the error category in the form of a int which is returned by either of the function yet the function which errors also puts a message on the top of the stack. You therefore can check the return value of luaL_dostring and get the error from the top of the stack but I always advise that people should at least call these two functions yourself or use a function which replaces luaL_dostring functionality, from there you can throw a typed none generic exception using the int return value from the failing function if you wish [4] :) 




Liam

------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev

_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: error exceptions

Jason McKesson
In reply to this post by strattonbrazil
On Aug 09, 2011 7:17 AM, Josh Stratton wrote:

> I'm trying to get error messages to display and I was following this
> tutorial.  However, I can't seem to get any error exceptions.  In a
> lua script I'm running, I have a print at the top and bottom and it's
> only hitting the top one, so I'm assuming there is some error in there
> I thought should raise an exception.
>
> http://www.nuclex.org/articles/5-cxx/1-quick-introduction-to-luabind
>
> void loadLuaFile(lua_State* state, QString fileName)
> {
>      QFile file(fileName);
>      file.open(QIODevice::ReadOnly);
>      QString lines = file.readAll();
>      //std://:cout<<  lines.toStdString()<<  std::endl;
>      try {
>          std::cout<<  "executing "<<  fileName.toStdString()<<
> "...\n-----------"<<  std::endl;
>          std::cout<<  lines.toStdString().c_str()<<  std::endl;
>          luaL_dostring(state, lines.toStdString().c_str());
>      } catch (const std::exception&TheError) {
>          std::cout<<  "*"<<  std::endl;
>          std::cout<<  TheError.what()<<  std::endl;
>      }
>
>      file.close();
> }
>
> ------------------------------------------------------------------------------
> uberSVN's rich system and user administration capabilities and model
> configuration take the hassle out of deploying and managing Subversion and
> the tools developers use with it. Learn more about uberSVN and get a free
> download at:  http://p.sf.net/sfu/wandisco-dev2dev
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
Luabind only throws exceptions if you call into Lua code *through*
Luabind. You're calling Lua code through the standard Lua API, therefore
no exceptions will be thrown. Instead, the typical Lua error handling
code will be used.

------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: error exceptions

Nigel Atkinson-2
In reply to this post by Willi Schinmeyer

On Wed, August 10, 2011 12:43 am, Willi Schinmeyer wrote:

> Am Dienstag, den 09.08.2011, 07:17 -0700 schrieb Josh Stratton:
>> so I'm assuming there is some error in there
>> I thought should raise an exception.
>
> Nope, errors don't usually raise exceptions, they just change the return
> value. Read the manual regarding luaL_dostring(), I don't know how to
> check its success off the top of my head.
 

 

luaL_dostring reurns 1 on error, and in that case you should find a string describing the problem at the top of the Lua stack.

Nigel


------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev

_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: error exceptions

strattonbrazil
Thanks for the responses.  What is the corresponding luabind call
similar to luaL_dostring that actually throws exceptions?

On Tue, Aug 9, 2011 at 3:22 PM, Nigel Atkinson <[hidden email]> wrote:

> On Wed, August 10, 2011 12:43 am, Willi Schinmeyer wrote:
>
>> Am Dienstag, den 09.08.2011, 07:17 -0700 schrieb Josh Stratton:
>>> so I'm assuming there is some error in there
>>> I thought should raise an exception.
>>
>> Nope, errors don't usually raise exceptions, they just change the return
>> value. Read the manual regarding luaL_dostring(), I don't know how to
>> check its success off the top of my head.
>
>
>
>
> luaL_dostring reurns 1 on error, and in that case you should find a string
> describing the problem at the top of the Lua stack.
>
> Nigel
>
> ------------------------------------------------------------------------------
> uberSVN's rich system and user administration capabilities and model
> configuration take the hassle out of deploying and managing Subversion and
> the tools developers use with it. Learn more about uberSVN and get a free
> download at:  http://p.sf.net/sfu/wandisco-dev2dev
>
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
>

------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: error exceptions

Jason McKesson
On Tuesday, August 09, 2011 3:28:14 PM, Josh Stratton wrote:

> Thanks for the responses.  What is the corresponding luabind call
> similar to luaL_dostring that actually throws exceptions?
>
> On Tue, Aug 9, 2011 at 3:22 PM, Nigel Atkinson<[hidden email]>  wrote:
>> On Wed, August 10, 2011 12:43 am, Willi Schinmeyer wrote:
>>
>>> Am Dienstag, den 09.08.2011, 07:17 -0700 schrieb Josh Stratton:
>>>> so I'm assuming there is some error in there
>>>> I thought should raise an exception.
>>>
>>> Nope, errors don't usually raise exceptions, they just change the return
>>> value. Read the manual regarding luaL_dostring(), I don't know how to
>>> check its success off the top of my head.
>>
>>
>>
>>
>> luaL_dostring reurns 1 on error, and in that case you should find a string
>> describing the problem at the top of the Lua stack.
>>
>> Nigel
>>
>> ------------------------------------------------------------------------------
>> uberSVN's rich system and user administration ca
pabilities and model

>> configuration take the hassle out of deploying and managing Subversion and
>> the tools developers use with it. Learn more about uberSVN and get a free
>> download at:  http://p.sf.net/sfu/wandisco-dev2dev
>>
>> _______________________________________________
>> luabind-user mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/luabind-user
>>
>>
>
> ------------------------------------------------------------------------------
> uberSVN's rich system and user administration capabilities and model
> configuration take the hassle out of deploying and managing Subversion and
> the tools developers use with it. Learn more about uberSVN and get a free
> download at:  http://p.sf.net/sfu/wandisco-dev2dev
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user

There is no single Luabind call tha
t does what luaL_dostring does. You
have to do all of the individual steps.

You have Lua compile the string into a chunk, using the standard Lua
API (no exceptions). Then, if it compiled successfully, you have to use
luabind::from_stack to convert the Lua chunk into a luabind::object
(note that it will still also be on the stack, so you'll have to deal
with that). Once it's a luabind::object, you can call it with
operator().

------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user