Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
add how to use this lib.
  • Loading branch information
tech-xiwi authored Feb 1, 2018
1 parent c53e66b commit e0cbe3d
Showing 1 changed file with 108 additions and 0 deletions.
108 changes: 108 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,110 @@
# xException
This is Pretty beautiful error log, You can listen the error and then to do special job!

# 使用样例

local x_error = require("xexception")

function listenError(...)

print("need to restart ...")

local temp = { ... }

local arg = select("1", temp)

--返回第一个参数和其之后的所有参数

for i=1,#arg do

-- print(arg[i])
end

end


x_error.setCallback(listenError)

--测试 tryCatchError

x_error.tryCatchError(function(arg)

for i=1,#arg do

print("tryCatchError arg"..i, arg[i])
-- error('error..')
n = n/nil
end

-- n = n/nil

end,10,11,12,"lua")

print()

-- 测试 catchException

x_error.catchException(function(arg)

for i=1,#arg do

print("catchException arg"..i, arg[i])
error('error..')
-- n = n/nil
end

-- n = n/nil

end,100,101,102,"lua") --输出为100,101,102,lua

print()


-- 测试使用x_error.try, x_error.catch 自定义逻辑

x_error.try {

function ()
error('hello error')
end
,
x_error.catch {
function(error)
print('custom error handler...',error)
end
}
}

# 输出日志

tryCatchError arg1     10
---------------------------------------- TRACKBACK START ----------------------------------------
stack traceback:
test.lua:18: attempt to perform arithmetic on a nil value (global 'n')
---------------------------------------- TRACKBACK END ----------------------------------------
need to restart ...

catchException arg1 100
---------------------------------------- TRACKBACK START ----------------------------------------
stack traceback:
[C]: in function 'error'
test.lua:27: in upvalue 'func'
---------------------------------------- TRACKBACK END ----------------------------------------
need to restart ...

custom error handler... test.lua:36: hello error

0 comments on commit e0cbe3d

Please sign in to comment.