Skip to content

moteus/lua-try

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lua-try

Licence Build Status Coverage Status

Simple exception support based on LuaSocket

You can read this article.

Also you can check out pure Lua implementation of this library - try-lua .

Usage

local try = require "try"

local protected_fun = try.protect(function(fname)
  local f -- local file handle
  
  -- define finalizer to close file
  local assert = try.new(function()
    if f then f:close() end
  end)

  -- now if `assert` raise error then
  -- `try` calls finalizer and protected function
  -- returns nil and error object

  f = assert(io.open(fname))

  assert(do_some_function(f))

  f:close()
end)