Error Handling

Error handling in the addon system can take on a couple of forms. First, addon developers can make use of the native Lua error handling mechanisms. For more information on how Lua enables error handling, take a look at the Lua documentation at http://www.lua.org.

In addition to the native error handling provided by Lua, the addon system provides the ability for addon developers to define a method inside of addons that will be called whenever an error occurs. If an addon developer includes a method in an addon named "OnError" that takes a single parameter, any time an error occurs, the addon system will invoke the OnError method and pass in a ScriptException object (sub-classed from System.Exception) that details the error. The error that is passed in will have two properties, in addition to the properties available on the System.Exception class. The properties are ScriptName, which represents the name of the addon that caused the error (the OnError message is only invoked for the addon that caused the original error, so this should always match the name of your addon), and ScriptMethod, which represents the name of the method in which the error occurred.

When the OnError method is called, the addon can access the ScriptException object to determine what happened or obtain debugging information. Addon developers are free to utilize the information provided using whatever methods are normally available to the given addon. For example, all addons have access to the LogDebug method, so one option is to use the ScriptException.InnerException.Message property in conjunction with LogDebug to output the error message to the host applications debug log.