[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: An interesting new ways to do errors
- From: "Dimiter \"malkia\" Stanev" <malkia@...>
- Date: Mon, 21 Nov 2011 21:05:13 -0800
Do you plan on releasing this with some license?
Is it okay if I put in my project (same license as lua and luajit)?
On 11/21/11 8:42 PM, Daurnimator wrote:
That errors should be resumable:
- for warnings: sometimes you just want to ignore them and continue
- some errors can be recovered with user input
So I had a grand idea: re-implement errors as we know them in lua;
- error raising functions (such as error and assert) are replaced
- pcall just becomes a wrapper around coroutine.create
I went and made a small library to try it; and it works great!
A few problems occured along the way:
- varargs + variable length return values are a bitch: so many
functions! everything has to be a tailcall too; or you blow the stack.
- xpcall becomes slightly incompatible with existing handlers: you
are no longer running in the error'd thread in the error handler: the
thread that had the error is passed in (and you can use this parameter
to get information with debug.getinfo()/debug.traceback()/etc
A few realisations came about:
- This wasn't only a system for adding resumable errors; it is a good
way to raise and catch errors overall
- You get yielding over pcall boundarys for free
- The standard lua error system is no longer needed: adding something
like this to the standard distribution may really simplify thing: “A
designer knows that he has achieved perfection not when there is
nothing left to add, but when there is nothing left to take away”
What do you think?
Would you use something like this in your own code?
Should the error system as we know it be replaced?