Skip to content
everloot

Lore archive · Warcraft Wiki, 2023 dump

API xpcall

Last wiki revision 2023-08-02

Executes a function in protected mode with a custom error handler. status, ... = xpcall(f, err [, ...])

false, errormsg = xpcall(f, err, arg1, arg2) true, ret1, ret2 = xpcall(f, err, arg1, arg2)

  • f: - The function that will be called.
  • err: - Error handler function to be used should f cause an error.
  • ...: - Optional arguments to be passed to the function.
  • status: - True if the function succeeded without errors.
  • ...
  • If status is, the return from the error function . This should generally be a string because the global handler for uncaught errors won't accept non-string errors, it would be replaced by "UNKNOWN ERROR".
  • if status is, the return values from the function.

calls function in protected mode, using as the error handler. Any error inside is not propagated; instead, catches the error, calls the function with the original error object, and returns a status code. Its first result is the status code (a boolean), which is true if the call succeeds without errors. In this case, also returns all results from the call, after this first result. In case of any error, returns false plus the result from.

  • Reference: Lua Manual

This is useful to call a function and continue regardless of any error, which would be caught and handled by showing it in the default error handler. Another example to illustrate the return values and optional arguments.

  • https://wowprogramming.com/docs/api/xpcall.html
  • https://www.lua.org/manual/5.2/manual.html#pdf-xpcall
  • https://www.lua.org/pil/8.4.html - Error Handling and Exceptions
  • https://www.lua.org/pil/8.5.html - Error Messages and Tracebacks

Source

https://warcraft.wiki.gg/wiki/API_xpcall · retrieved 2023-11-13 · CC BY-SA 4.0

Converted from wikitext with templates, tables and images removed, so some sentences may be missing values.

This archive predates WoW: Forever. For collected gameplay facts see the Forever database. Search the archive.