lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Andrew Starks once stated:
> On Wed, Sep 10, 2014 at 8:39 PM, Sean Conner <sean@conman.org> wrote:
> 
> > It was thus said that the Great Andrew Starks once stated:
> > >
> > > In practice, I find that it's hard to tell what is happening, especially
> > in
> > > a coroutine, and especially if I use the `nil, error` approach. I
> > generally
> > > like my errors to be loud and obvious and haven't had a ton of success
> > with
> > > 'quietly moving on.'
> > >
> > > Soo..... what do smart people do?
> >
> >   One other thing I've done.  The the one place I do call lua_pcall(), I
> > made sure the following function is on the stack:
> >
> >         function stackdump()
> >           local stack = {}
> >           for i = 1 , 10 do
> >             local info = debug.getinfo(i,"Sl")
> >             if not info then break end
> >             table.insert(stack,string.format("
> > [%s(%d)]",info.source,info.currentline))
> >           end
> >
> >           syslog('debug',"stack=%s",table.concat(stack))
> >         end
> >
> >   It's enough to pin point the place of the crash.
> >
> >   -spc (Then again, I'm not using the sample lua interpreter, but have Lua
> >         embedded in the application)
> >
> >
> Your project sounds like a similar situation to what we're doing. Also,
> this is a great idea.
> 
> Given that we're using many coroutines, I think that we're better off
> erring on the side of 'error' and not 'nil, error'.

  That does follow the Erlang "fail fast, fail hard" philosophy, and that's
used in telecom!  [1]

> Still, there are tough calls though, like If a warning from one function
> causes any ambiguity about the state in another. Maybe it isn't.... just
> crash.

  You would have the same issue with system threading---if one thread causes
any ambiguity about the state in another system thread, so that's nothing
new there. [2]

> Are there interesting differences between how you think about / deal with
> error handling in C/C++ vs. Lua?  Accepting that the mechanisms are
> different, do you do more "try to recover" code in C?

  I don't program in C++, so I don't use exceptions.  In regard to error
handling, I tend to handle errors in Lua like I do in C.  And I don't really
do "recover" code in C.  [2][3]

	-spc

[1]	Granted, it presupposes that what crashed is an Erlang
	thread/process, and that there is some other Erlang thread/process
	monitoring the thread/process and can log/restart/whatever when the
	crash happens.

[2]	Back in college, I was working on a project where I was overly
	concerned about logging errors.  If I couldn't successfully log
	(disk was filled, printer off line, printing to the console was
	useless as there wasn't a console, etc) then what?  I asked one of
	my instructors about the case, and he said, "if you don't know how
	to handle an error, don't check for it."

	That wasn't what I was expecting and it bugged me, but over the
	years, I've come to see the wisdom in that.

[3]	I log such errors though.