lide.error¶
[lide.core] ^0.01This module is loaded with
lide.coreit’s part of framework into thelide.errormodule we will find the necessary functions to robust error handling implemented in Lua.local try, catch = lide.error.try, lide.error.catch; try { function( ) ... end, catch { function( err ) print(err); end }};
Creation and handling exceptions:¶
It is also possible to be more precise and to find the type of error we are looking for, that’s what the exceptions are for.
We can create new exceptions and control them with the catch function.
local TypeError = lide.error.newException 'TypeError'
try{
function()
function foo(text)
if type(text) ~= 'string' then
TypeError '"text" It\'s not string type.'
end
end
foo(1) -- We run the function with a number as an argument for our error to propagate.
end,
catch {
function( err )
if err:isa(TypeError) then -- We use the "isa" method to compare what type of error / exception it is.
print(err.traceback)
end
end
}
}
lide.error.try¶
Within this function we will put the piece of code that could have an error.
| nil | lide.error.try ( function try_code ) |
lide.error.catch¶
OptionalWithin this function we will put the code that will be executed in case of error.
| nil | lide.error.catch ( function catch_code ( Exception exception ) ) |
lide.error.finally¶
OptionalHere we should put cleaning code
| nil | lide.error.finally ( function finally_code ) |
lide.error.newException¶
Create an exception
| Exception | lide.error.newException ( string sExceptionName, string sDefaultErrMsg ) |