사용자 정의 예외 핸들러 설정

예외 핸들러를 설정하여 규칙 조건 및 조치에서 예외 처리를 사용자 정의할 수 있습니다. CustomExceptionHandler API를 구현할 때, 예외가 무시되거나 다시 처리될 수 있습니다.

이 태스크 정보

기본 엔진 동작은 예외 처리 시 중지하는 것입니다. CustomExceptionHandler API를 구현하면, 엔진이 계속해서 규칙을 처리할 수 있도록 기본 엔진 동작을 강제 실행하거나 예외를 무시하도록 선택할 수 있습니다.

CustomExceptionHandler를 활성화하려면, XOM에서 인터페이스를 구현한 후 Rule Designer에서 구현 클래스 이름을 지정해야 합니다.

프로시저

  1. XOM에서 CustomExceptionHandler 인터페이스를 구현하십시오. 다음 예제에서, 사용자 정의 예외 핸들러가 NumberFormatException의 예외를 다시 처리합니다.
    package com.acme;
    import ...
    
    public class MyCustomExceptionHandler implements CustomExceptionHandler {
    
      static Logger logger = Logger.getLogger(MyCustomExceptionHandler.class.getName());
    
      /**
       * The custom exception handler must contain a default constructor.
       */
      public MyCustomExceptionHandler() {
      }
    
      @Override
      public void handleConditionException(Exception e) throws Exception {
        if (e instanceof NumberFormatException) {
          // ignore number format exception
        } else {
          // rethrow the exception, it will stop the engine execution
          throw e;
        }
      }
    
      @Override
      public void handleActionException(Exception e, RuleInstance ruleInstance) throws Exception {
        if (e instanceof NumberFormatException) {
          // ignore number format exception and log
          if (logger.isLoggable(Level.INFO)) {
            logger.log(Level.INFO,
                "Exception while executing action of rule " + ruleInstance.getRuleName(), e);
          }
        } else {
          // rethrow the exception, it will stop the engine execution
          throw e;
        }
      }
    }
  2. Rule Designer를 여십시오.
  3. 규칙 프로젝트 특성 창의 Rule Engine 패널에서, 사용자 정의 예외 핸들러 이름을 입력하십시오. 예를 들어, 사용자 정의 예외 핸들러 필드에 com.acme.MyCustomExceptionHandler를 입력하십시오.
  4. 확인을 클릭하십시오.

결과

사용자 정의 예외 핸들러는 엔진 시작 시 작성되고 엔진 재설정 시 제거됩니다.