确保执行(finally)

异常处理

local function throw_if_true(param)
  local ok = pcall(function()
    if param then
      error("test exception", 0)
    end
  end)
  if not ok then
    print("except")
  end
  -- No finally: this code follows pcall,
  -- so it runs after an error and without it
  print("finally")
end

throw_if_true(true)
-- except
-- finally
throw_if_true(false)
-- finally