vin-spiegel / lua-try-catch

simple try catch module using middleclass

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lua-try-catch

Simple try catch module using middleclass by kikito

Usage

local try = require("try-catch").try

try(function()
    error("raise error")
end)
.catch(function(ex)
    print(ex.message)
    print(ex.traceback)
end)
.finally(function ()
    print("finally do something...")
end)

Customize Exception

local class = require("middleclass")
local tryCatch = require("try-catch")

---Set Custom Exception Class
local customException = class("exception", tryCatch.exceptionBase)

function customException:initialize(msg)
    self.base(msg)
    self.message = "this is customException: " .. msg
end

tryCatch.options.customException = customException
try(function()
    error("raise error")
end)
.catch(function(ex)
    print(ex.message) --> this is customException: example.lua:18: raise error   
end)

License

MIT

About

simple try catch module using middleclass

License:MIT License


Languages

Language:Lua 100.0%