feat: add error handling part #3
13
README.md
13
README.md
@@ -499,6 +499,7 @@ local function divideANumberByAnOther(a, b)
|
||||
return a / b -- it would be better to validate parameters, but this is for example purposes
|
||||
end
|
||||
|
||||
|
||||
-------------------------------
|
||||
-- First scenario: error case
|
||||
-------------------------------
|
||||
@@ -511,8 +512,6 @@ end
|
||||
-- Output: An error has occured :
|
||||
|
||||
|
||||
|
||||
|
||||
-------------------------------
|
||||
-- Second scenario: valid case
|
||||
-------------------------------
|
||||
@@ -527,10 +526,9 @@ end
|
||||
|
||||
|
||||
|
||||
|
||||
----------------------------------
|
||||
---------------------------------------------------------------------
|
||||
-- Third scenario: combine pcall with assert for critical operations
|
||||
----------------------------------
|
||||
---------------------------------------------------------------------
|
||||
|
||||
local function readFile(fileName)
|
||||
local fileToRead = assert(io.open(fileName, "r"), "Impossible to read the file")
|
||||
@@ -551,10 +549,9 @@ end
|
||||
|
||||
|
||||
|
||||
|
||||
--------------------------------
|
||||
-----------------------------------------------------------------------
|
||||
-- Fourth scenario: pcall with a function that returns multiple values
|
||||
--------------------------------------
|
||||
-----------------------------------------------------------------------
|
||||
local function sumAndProduct(a, b)
|
||||
return a + b, a * b
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user