lua-users home
lua-l archive

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

On 7/11/14, Steven Degutis <> wrote:
> For what it's worth, I haven't had to use @try to wrap any of my APIs
> so far, and have not had any bug reports from users about exceptions
> either. Then again, I'm not using an ObjC bridge, but writing a Lua
> API that wraps ObjC without such tight coupling.

It becomes a problem when something throws an exception, whether it be
from Cocoa, or a 3rd party library or your own stuff. And remember
that these can be written in in Obj-C or C++, outside your control if
you allow people to call native stuff or add their own modules/code.

Live-coding/REPL tends to trigger these cases more often as you are
more likely to call an API incorrectly and trigger an exception which
will corrupt the state of your program if Lua is in the middle of
something when this happens and you will not be able to continue.

I've filed (high) hundreds of Apple bugs on radar over the past
decade. I've seen more than my share of Apple bugs. Exceptions being
thrown that our out of your control can and do happen. An example is I
recall pushing some things with Core Animation that sometimes could
create race conditions and trigger exceptions outside of your control.
This is just some basic transition, not worthy of bringing down your
whole program so you want to catch it.

Changing pcall to use @try/@catch has pretty much no downside (besides
the work needed to do so). You get zero-cost exceptions which means
your initial pcall @try is zero-cost/free (setjump is much more
expensive...yes, I did benchmark). It allows you to handle the above
cases. And it handles C++ exceptions for free without needed to
compile Lua differently and deal with all the C++ unstable ABI hell.
Finally, if you're not dealing with Obj-C or any thing that throws
exceptions, it doesn't get in the way and your program still works
like before (but you get the benefit that your initial pcall's are
still zero-cost).

Beginning iPhone Games Development