Lua中 assert、pcall 的錯誤處理

自己百度吧


--忽律錯誤,繼續執行
function test1()
	pcall(
	function()
		print(d[1]); --d,table並不存在
	end)
	print("OK");
end
test1()




--忽律錯誤,友好顯示錯誤,並繼續執行
function test()
	print(d[1]); --d,table並不存在
end


local status, errors = pcall(test);
if status then
	print("正常");
else
	print("函數出錯了");
	print(errors);
end


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章