error() in 5.1

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

error() in 5.1

Reuben Thomas-5
By experimentation, I just found that error() produces no output (just
what I wanted), but the manual doesn't document this case. Is this an
oversight, or is the behaviour non-standard? (I'm using John Belmonte's
Debian package.)

--
http://rrt.sc3d.org/ | canonize, v.  to sanctify a dead sinner (Bierce)
Reply | Threaded
Open this post in threaded view
|

Re: error() in 5.1

Petite Abeille

On Mar 29, 2006, at 17:04, Reuben Thomas wrote:

> By experimentation, I just found that error() produces no output (just
> what I wanted), but the manual doesn't document this case. Is this an
> oversight, or is the behaviour non-standard? (I'm using John
> Belmonte's Debian package.)

I would guess "non-standard", at least in the lua interpreter.

error( "Duh!" )

lua: TestTable.lua:322: Duh!
stack traceback:
         [C]: in function 'error'
         TestTable.lua:322: in main chunk
         [C]: ?


Cheers

--
PA, Onnay Equitursay
http://alt.textdrive.com/

Reply | Threaded
Open this post in threaded view
|

Re: error() in 5.1

Reuben Thomas-5
On Wed, 29 Mar 2006, PA wrote:

> On Mar 29, 2006, at 17:04, Reuben Thomas wrote:
>
>> By experimentation, I just found that error() produces no output (just what
>> I wanted), but the manual doesn't document this case. Is this an oversight,
>> or is the behaviour non-standard? (I'm using John Belmonte's Debian
>> package.)
>
> I would guess "non-standard", at least in the lua interpreter.
>
> error( "Duh!" )
>
> lua: TestTable.lua:322: Duh!
> stack traceback:
>        [C]: in function 'error'
>        TestTable.lua:322: in main chunk
>        [C]: ?
>

You misunderstand: I'm talking about error called with no arguments.
error with arguments works as advertised in the manual.

--
http://rrt.sc3d.org/ | Floc: an egregiously good aperitif
Reply | Threaded
Open this post in threaded view
|

Re: error() in 5.1

Petite Abeille

On Mar 29, 2006, at 18:06, Reuben Thomas wrote:

> You misunderstand: I'm talking about error called with no arguments.
> error with arguments works as advertised in the manual.

I see. Simply invoking error() without argument doesn't produce any
output here as well, but it does raise an exception:

function test()
         error()
end

print( pcall( test ) )

 > false   nil

Hmmm...

Cheers

--
PA, Onnay Equitursay
http://alt.textdrive.com/

Reply | Threaded
Open this post in threaded view
|

Re: error() in 5.1

Roberto Ierusalimschy
In reply to this post by Reuben Thomas-5
> By experimentation, I just found that error() produces no output (just
> what I wanted), but the manual doesn't document this case. Is this an
> oversight, or is the behaviour non-standard? (I'm using John Belmonte's
> Debian package.)

It is standard (now). But this is not a property of error (although it
colaborates), but of lua.c. Since Lua 5.0 (?) error can throw any object
as the "error message". In 5.1, error() throws nil as the error message.
(This is not big deal; several functions now handle nil and no-argument
in the same way.)  The main change is that lua.c checks the error object
and, if it is nil, it does not show anything. (See 'report' in lua.c.)

-- Roberto
Reply | Threaded
Open this post in threaded view
|

Re: error() in 5.1

Petite Abeille

On Mar 29, 2006, at 18:40, Roberto Ierusalimschy wrote:

> The main change is that lua.c checks the error object
> and, if it is nil, it does not show anything. (See 'report' in lua.c.)

Hmmm... this is a bit disconcerting. What's the rational behind this
behavior? After all, an error is an error, message or not.

Cheers

--
PA, Onnay Equitursay
http://alt.textdrive.com/

Reply | Threaded
Open this post in threaded view
|

Re: error() in 5.1

Roberto Ierusalimschy
> >The main change is that lua.c checks the error object
> >and, if it is nil, it does not show anything. (See 'report' in lua.c.)
>
> Hmmm... this is a bit disconcerting. What's the rational behind this
> behavior? After all, an error is an error, message or not.

The rationale is to allow errors without messages :) An error is an error,
and a message is a message. If the error does not have a message, it
probably does not want one.

-- Roberto
Reply | Threaded
Open this post in threaded view
|

Re: error() in 5.1

Petite Abeille

On Mar 29, 2006, at 20:12, Roberto Ierusalimschy wrote:

>>> The main change is that lua.c checks the error object
>>> and, if it is nil, it does not show anything. (See 'report' in
>>> lua.c.)
>>
>> Hmmm... this is a bit disconcerting. What's the rational behind this
>> behavior? After all, an error is an error, message or not.
>
> The rationale is to allow errors without messages :) An error is an
> error,
> and a message is a message. If the error does not have a message, it
> probably does not want one.

Or perhaps I mistyped the variable name representing the message. Or I
just would like to throw an exception and see the stack trace as I
usually do. Or...

I thought that error() always added the error position:

"With level 1 (the default), the error position is where the error
function was called"
http://www.lua.org/manual/5.1/manual.html#pdf-error

Isn't error() the equivalent of error( nil, 1 )?

Isn't the purpose of the 'level 0' parameter to "avoids the addition of
error position information to the message"?

Wouldn't a 'silent' error look like this:

error( nil, 0 )

Very confusing :/

Cheers

--
PA, Onnay Equitursay
http://alt.textdrive.com/