Skip to content

Commit

Permalink
Update README.md [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
moteus committed Nov 10, 2014
1 parent f47ff4d commit ea978de
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
lua-try
=======
[![Licence](http://img.shields.io/badge/Licence-MIT-brightgreen.svg)](LICENSE)
[![Build Status](https://travis-ci.org/moteus/lua-try.svg?branch=master)](https://travis-ci.org/moteus/lua-try)
[![Coverage Status](https://coveralls.io/repos/moteus/lua-try/badge.png?branch=master)](https://coveralls.io/r/moteus/lua-try?branch=master)

Simple exception support based on LuaSocket

##Usage
```Lua
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)

```

0 comments on commit ea978de

Please sign in to comment.