lua-users home
lua-l archive

Re: Modifing try-catch statement

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


On Sat, Sep 18, 2010 at 09:16:59AM +1000, James Rhodes top-posted:
> I don't want Python, I want to modify Lua. The standard try-catch
> patch is not flexible enough for my uses, as native functions in my
> engine will return different types of exceptions (and it's important
> to differentiate the type since not all thrown values will have a
> Message attribute that can be read).
Then write a function that dispatches them depending on type. Perhaps
something like...
try
 ...
catch e do
 dispatch(e) {
 extype1 = function(e) ... end,
 extype2 = function(e) ... end,
 extype3 = function(e) ... end
 }
end
This has the bonus of not needing to fidget with the patch. In fact,
adjust this "dispatch" function a little more, and you could end up with
this syntax, and not need the patch at all:
try(func, ..., {
	extype1 = function(e) ... end,
	...
})
B.

AltStyle によって変換されたページ (->オリジナル) /