如何捕获elua(即NodeMCU)中的错误
假设我正在导入具有以下内容的内容:如何捕获elua(即NodeMCU)中的错误,lua,try-catch,nodemcu,Lua,Try Catch,Nodemcu,假设我正在导入具有以下内容的内容: t = require("ds18b20") t.setup(1) temperatura = t.read() 如何捕获导入失败之类的错误 执行pcallt.setup1之类的操作只会返回一个语法错误。如果该错误是由于不需要查找ds18b20而引起的,那么您可以执行以下操作 ok, t = pcall(require, "ds18b20") if not ok then -- handle error, t has error message else
t = require("ds18b20")
t.setup(1)
temperatura = t.read()
如何捕获导入失败之类的错误
执行pcallt.setup1之类的操作只会返回一个语法错误。如果该错误是由于不需要查找ds18b20而引起的,那么您可以执行以下操作
ok, t = pcall(require, "ds18b20")
if not ok then
-- handle error, t has error message
else
-- can use t
end