“Lua Catch Error” Kode Jawaban

coba kecuali Lua

require "try-catch"

try {
   function()
      error('oops')
   end,

   catch {
      function(error)
         print('caught error: ' .. error)
      end
   }
}
Naughty Nightingale

Lua Catch Error

-- The pcall (f, arg1, ...) function calls the requested function in
-- protected mode. If some error occurs in function f, it does not throw
-- an error. It just returns the status of error. A simple example using
-- pcall is shown below.

Live Demo
function myfunction ()
   n = n/nil
end

if pcall(myfunction) then
   print("Success")
else
	print("Failure")
end
Ugliest Unicorn

Jawaban yang mirip dengan “Lua Catch Error”

Pertanyaan yang mirip dengan “Lua Catch Error”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya