1 Reply Latest reply: Feb 20, 2013 4:42 PM by Ayush Ganeriwal RSS

    JAVA BEANSHELL EXCEPTION HANDLING

    grimrand
      Hi

      still new to ODI

      I have created a java beanshell script in ODI which calls a simple java class, cars, then sets the no of seats to a value designed to raise an exception. Exception raised but procedure works OK,

      How can I register the fact that it has failed through exception handling? (It is possible that my java exception handling isn't quite right)

      The no of seats has no effect on the success/failure of the ODI procedure, but the log shows that the exception is caught !
      any assistance gratefully received.


      Regards

      Terry




      cars class: (added to agent start)
      ====================


      public class cars {
      private int seats;

      public void setSeats (int seats) throws tooManySeatsException {
      if (seats) < 100) {
      this .seats = seats;
      } else {
      throw new tooManySeatsException("Too many seats");
      }

      public int getSeats () {
      return this.seats;
      }


      class tooManySeatsException extends Exception {

      public tooManySeatsException (String msg){
      super();
      }
      }
      }






      Java beanshell procedure in ODI
      ====================

      import cars;

      public class carsTest {

      public carsTest(){
      }

      public void init(){
      cars c = new cars();

      c.setSeats(20);
      //c.setseats(200);

      }

      }


      try {
      carsTest ct = new carsTest();
      ct.init();
      } catch (Exception e) {

      throw Error (e);
      }
        • 1. Re: JAVA BEANSHELL EXCEPTION HANDLING
          Ayush Ganeriwal
          Your code throws exception when you set value >100 but you are setting 20 thus it would not throw exception.

          In the procedure step you can uncheck "Ignore error" flag to let execution failed on throwing any exception from your code. If you check that flag then the execution would not fail rather lease the task in warning state.