Created
February 11, 2013 23:18
-
-
Save martindevans/4758543 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function try(f, catch_f, ...) | |
local status, exception = pcall(f, unpack(arg)) | |
if not status then | |
catch_f(exception) | |
end | |
end | |
function foo(a, b) | |
return a < b; | |
end | |
--Triggers an error | |
--foo(1, nil); | |
--Triggers an error, and handles it | |
--try(foo, function(e) print("CUSTOM ERROR HANDLER! " .. e); end); | |
--Works just fine | |
--try(foo, function(e) print("error! " .. e); end, 1, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment