This post will explain the process to raise the custom exception in ODI.
Process:
- Create a variable to store the custom error message
- Create a procedure to read the error message from the variable and raise the exception.
- Create a package to set the value in the custom error variable and execute the raise exception procedure.
Steps:
Create a new variable to store the custom error message:
We don’t need to select a schema or refreshing query, as this variable value will be set in the Package.
Create the procedure “Raise Custom Exception” and select the Target technology as “Jython”.
Go to Details, add step and add the code below in the “Command on Target” tab
<% String errMesg=”>>>>>>> ” +odiRef.getOption(“OBI_ERROR_MESSAGE”) + ” <<<<<<<<“; %>
<$
// New Class being defined for raising custom exceptions
//————————————————————–New Class TableException—————————————-
public class CustomException extends Exception
{
String errmesg;
public CustomException()
{
super(); // call superclass constructor
errmesg = “CustomException:Unknown Error Occured”;
}
// Constructor with the error message
public CustomException(String err)
{
super(err); // call super class constructor
errmesg = err; // save message
}
// public method, callable by exception catcher. It returns the error message.
public String getError()
{
return errmesg;
}
}//end of class CustomException
String mesg=”<%=errMesg%>”;
CustomException custErr=new CustomException(mesg);
throw custErr;
$>
Create a new package ‘Raise Previous Incremental Load Failed Exception’, add ERROR_MESSAGE variable to the package and set the variable value to the required custom error message.
Add a raise custom exception package
Execute this package. It will pass the value in variable ERROR_MESSAGE to Raise the custom exception procedure, and it throws the exception as below:
We can use same variable “ERROR_MESSAGE” and Procedure “Raise Custom Exception” to generate different custom exceptions, however, we need to create a separate package for each custom error message.