Skip to content

Instantly share code, notes, and snippets.

@skwerlman
Forked from cwarden/example-try-catch.lua
Last active March 20, 2016 22:47
Show Gist options
  • Save skwerlman/0f9cb5ee9da9aa322e45 to your computer and use it in GitHub Desktop.
Save skwerlman/0f9cb5ee9da9aa322e45 to your computer and use it in GitHub Desktop.
local try = require "try"
try(
function()
error('oops')
end
):catch(
function(err)
print('caught error: ' .. err)
end
)
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