Skip to main content
Version: 2024.1

Exception handling

Best practice when an exception occurs it is not to propagate it further but to handle it in the code of the extension. In order to mark the action as failed, set property args.HasErrors to true and then log detail of the exception. When args.HasErrors is set to true then the transaction in which the action is executed will be rolled back. If exception is not handled on the extension side then by default the entire callstack of the error will be returned to the user
More about logging and returning messages to user available here.

An example of an action with properly implemented exception handling.

public override async Task RunAsync(RunCustomActionParams args)
{
try
{
ActionLogic();
}
catch(Exception ex)
{
args.HasErrors = true;
args.Message = "An error occurred, more infomation in the logs";

//Log into document history
args.LogMessage = ex.ToString();

//Or log by PluginLogger
args.Context.PluginLogger.AppendInfo(ex.ToString());
}
}