Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何捕获elua(即NodeMCU)中的错误_Lua_Try Catch_Nodemcu - Fatal编程技术网

如何捕获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