--這里是注釋 --[[ 功能備注:lua快速體驗,學習,了解語法(除錯,類似try-catch) 創建時間:2020-6-27 創建人:pcw --]] print("--------------------------------"); print("類似throw exception(該方法拋例外之后,整個代碼檔案不往下走.)"); function addTestThrowException(a) assert(type(a) == "number", "a 不是一個數字") --例外之后,后面的代碼不執行 return a*a; end print(addTestThrowException(5)); --[[ 輸出結果: 類似throw exception 25 ]] --print(addTestThrowException("ab")); --[[ 解開上面的注釋,輸出結果: lua: Lua-除錯.lua:10: a 不是一個數字 stack traceback: [C]: in function 'assert' Lua-除錯.lua:10: in function 'addTestThrowException' Lua-除錯.lua:19: in main chunk [C]: ? ]] print("--------------------------------"); print("pcall:類似try-catch但不提供 除錯資訊"); print("pcall(addTestThrowException,5)=",pcall(addTestThrowException,5)); print("pcall(addTestThrowException,\"a\")=",pcall(addTestThrowException,"a")); print("--------------------------------"); print("xpcall類似try-catch但且提供除錯資訊 "); local function addTestThrowException2(a) print(a); return a*a; end function processException(err) --debug.debug(); --print(debug.debug()); --print("ERROR:",err); --print(debug.getinfo(1)) debug.traceback(); return false; end print(addTestThrowException2(5)); xpcall(addTestThrowException2,processException,5);
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/4989.html
標籤:C++
上一篇:快速體驗,學習lua(一種可嵌入c++,c#,android,object-c等并進行互調支持熱更新的腳本)的入門除錯系列(2)
下一篇:基礎練習(01)閏年判斷
