2

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.

dda
  • 6,030
  • 2
  • 25
  • 34
Nephilim
  • 494
  • 5
  • 25

1 Answers1

4

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
lhf
  • 70,581
  • 9
  • 108
  • 149