15 July, 2012

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");  


Many Thanks to Steve Muench for his recommendation and advice.
Steve advised me to use oracle.jbo.ValidationException instead  of the more general oracle.jbo.JboException as It is best to let framework know when you throw that your exception is validation-related.


Original Tip from Steve
" One tip is that if you plan to use this for a validation exception as your example shows, it should really extend oracle.jbo.ValidationException instead of the more general JboException. The framework treats validation exceptions specially in some circumstances, so it's best to let the framework know when you throw that your exception is validation-related, if in fact it is one of those."


Thanks

2 comments:

  1. ملاحظة ستيف كانت شيئاً جديداً علي
    عموماً شكراً لك على المقالة

    تحياتي

    ReplyDelete

ADF : Scope Variables

Oracle ADF uses many variables and each variable has a scope. There are five scopes in ADF (Application, Request, Session, View and PageFl...