PDA

View Full Version : error, pcall, Lua and AMS5


humdingerx
11-16-2004, 08:53 PM
I've been exploring Lua a little and noticed it's error handling throw/catch mechanism using error()/pcall() I've successfully used this in an AMS 5 project :yes I'm not really a great programmer but is there any way to get an error handler of my own implemented and running automatically?

i.e. instead of:
--------------------------------------------------------------------------
function foo()
-- attempt to perform arithmetic on a string causes exception
a = 'a'+1;
-- this bit is not reached!
return "All done!";
end

local status, err = pcall(foo);

Dialog.Message("Result of foo function", err, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);

-- execution continues!
--------------------------------------------------------------------------

I was wondering if it's possible to extend/override the default behaviour of pcall somehow so it calls my own error handler function (which I could define elsewhere?) Any ideas/example code much appreciated!