Skip to content

Instantly share code, notes, and snippets.

@martindevans
Created February 11, 2013 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martindevans/4758543 to your computer and use it in GitHub Desktop.
Save martindevans/4758543 to your computer and use it in GitHub Desktop.
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