Let's say I'm importing something with:
t = require("ds18b20")
t.setup(1)
temperatura = t.read()
How do I catch an error like "Failed import"?
Doing stuff like pcall(t.setup(1)) just returns a syntax error.
If the error is raised by require
not finding ds18b20
, then you can do
ok, t = pcall(require, "ds18b20")
if not ok then
-- handle error, t has error message
else
-- can use t
end