Handling Exceptions

  • Updated

Prerequisites: A valid RuleSession, a Try block wrapped around InRule SDK code to load state and execute rules.
Namespaces: InRule.Runtime, InRule.Common.Exceptions, InRule.Repository
Classes: RuleException, CompileException, CompilerError, RuntimeException
See Also: Basic Example of Creating a RuleApplication in Code
References: InRule.Runtime.dll, InRule.Common.dll

Below are the common exceptions to handle compile errors, runtime errors and also the RuleException, which is the base class for all InRule exceptions.  They are listed in the order in which they should be implemented.

The individual values in the AuthoringErrorCode and RuntimeErrorCode enumerations may change in future versions of InRule.

Note: See RuleException class for a complete list of InRule exceptions.

Handling compiler exceptions

// Catching compile exceptions
catch (CompileException ex)
{
    foreach (CompileError err in ex.Errors)
    {
        if (err.AuthoringErrorCode == AuthoringErrorCode.SqlQueryParameterTypeIsInvalid)
        {
            // React
        }
    }
}
Handling integration exceptions

// Catching integration exceptions
catch (IntegrationException ex)
{
    if (ex.RuntimeErrorCode == RuntimeErrorCode.StateUnableToBindToMember)
    {
        // React
    }
}
Handling base exceptions

// Base class exception; can be used to catch all InRule exceptions
catch (RuntimeException ex)
{
    foreach (ErrorLogMessage err in ex.ErrorMessages)
    {
        if (err.RuntimeErrorCode == RuntimeErrorCode.AppSettingsSectionMissingOrMalformed)
        {
            // React
        }
    }

Was this article helpful?

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.