-
-
Save skwerlman/0f9cb5ee9da9aa322e45 to your computer and use it in GitHub Desktop.
OO fork of https://gist.github.com/cwarden/1207556
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
local try = require "try" | |
try( | |
function() | |
error('oops') | |
end | |
):catch( | |
function(err) | |
print('caught error: ' .. err) | |
end | |
) |
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
local function try(something) | |
local obj = {} | |
function obj:catch(anotherThing) | |
if not self.status then | |
return anotherThing(self.result) | |
else | |
return self.result | |
end | |
end | |
obj.status, obj.result = pcall(something) | |
return obj | |
end | |
return try |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment