Friday, 26 April 2013

Custom Exception in ADF

sometimes in your business logic you want to throw
an exception regarding business requirements not Java syntax coding exception.
For example you want to raise an exception that birthday is not later than hire date.

To implement this cased in ADF I prefer the below steps.
1- Create new "ApplicationException" class and extend oracle.jbo.JboException


Create new custom class which extends oracle.jbo.JboException for adding your custom code to exception later.
import oracle.jbo.JboException;
import oracle.jbo.common.ResourceBundleDef;
public class ApplicationException extends JboException { 

 public ApplicationException(Class class1, String string, Object[] objects, Exception[] exceptions) { 

super(class1, string, objects, exceptions); 
 } 
 public ApplicationException(Class class1, String string, Object[] objects, JboException[] jboExceptions) 

 super(class1, string, objects, jboExceptions); 
 } 
 public ApplicationException(ResourceBundleDef resourceBundleDef, String string, Object[] objects) { 
 super(resourceBundleDef, string, objects); 
 } 
 public ApplicationException(Class class1, String string, Object[] objects)
 { 
 super(class1, string, objects); 
 } 
 public ApplicationException(Throwable throwable) 

 super(throwable); 
 }
 public ApplicationException(String string) { super(string); 
 }
 public ApplicationException(String string, String string1, Object[] objects) 

 super(string, string1, objects); 
 }
 }


2- Throw an exception in your code using the new class.
Anywhere in your code you can throw an exception using the following code


throw new ApplicationException("birthday should not later than hire date");

No comments:

Post a Comment