Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Engineering

Exception Handling in a Common Application Framework Addin

Exception Handling in a Common Application Framework Addin

  • Last UpdatedJun 02, 2022
  • 2 minute read

The code of all components of a Common Application Framework (CAF) Addin is executed within the event loop of the host AVEVA program. Any exception raised within the Addin code, or any code called by it, that is not caught by the addin code itself will have to be handled in the event loop. The AVEVA host has effective ways to handle some classes of exceptions - namely PdmsExceptions and PMLNetExceptions. In the situation where the host program is in the process of executing Programmable Macro Language (PML), then the PML first has an opportunity to handle the exception itself. If the PML does not handle the exception, or if no PML is currently being executed, the host program handles these exceptions by notifying the user of the exception text and number interactively via the Status Bar, MessageBoxes or the CommandLine display as appropriate. Event loop processing then continues normally.

For all other classes of exception the host event loop has no standard procedure and the outcome is that the host program terminates untidily. It is therefore very poor programming style to allow general exceptions to escape from the Addin. A relatively easy way to prevent this is to trap exceptions systematically at every entry point between the host event loop and the component interfaces - for example in every Command.Execute function:

/// <summary>

/// Execute

/// </summary>

public override void Execute()

{

     try

     {

          // Do the required function.

             DoTheJob();

     }

     catch (System.Exception ex)

     {

          // Pass on PdmsExceptions and PMLNetExceptions.

          // Handle all others:

          // (perhaps by raising a PdmsException).

     }

}

private void DoTheJob()

{

     // Do the required function...

}

This recommendation does not, of course, replace the routine practice of handling exceptions at the appropriate points within the Addin code when they are anticipated and can be dealt with effectively. It simply provides a safety net for unanticipated and otherwise unhandled exceptions.

TitleResults for “How to create a CRG?”Also Available in