Skip to content

Instantly share code, notes, and snippets.

@alex-eri
Forked from cwarden/example-try-catch.lua
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save alex-eri/b35e7c1bb66afc49256c to your computer and use it in GitHub Desktop.

Select an option

Save alex-eri/b35e7c1bb66afc49256c to your computer and use it in GitHub Desktop.

Revisions

  1. @cwarden cwarden revised this gist Sep 9, 2011. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion example-try-catch.lua
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    require "try-catch"

    try {
    function()
    error('oops')
    @@ -8,4 +10,4 @@ try {
    print('caught error: ' .. error)
    end
    }
    }
    }
  2. @cwarden cwarden created this gist Sep 9, 2011.
    11 changes: 11 additions & 0 deletions example-try-catch.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    try {
    function()
    error('oops')
    end,

    catch {
    function(error)
    print('caught error: ' .. error)
    end
    }
    }
    11 changes: 11 additions & 0 deletions try-catch.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    function catch(what)
    return what[1]
    end

    function try(what)
    status, result = pcall(what[1])
    if not status then
    what[2](result)
    end
    return result
    end