wood burning stoves 2.0*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Checked application exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Checked application exception" Watch "Checked application exception" New topic
Author

Checked application exception

Alexandre Fradin
Greenhorn

Joined: Jul 29, 2008
Posts: 11
Hi,

Application exceptions that are checked exceptions
may be defined as such by being listed in the throws clauses of the methods of the bean�s business
interface.

Does it mean that an Exception may be a Application exception for a business method and a system exception for an other one, for example :




Is my example true?

Thanks for help.

[ August 11, 2008: Message edited by: Alexandre Fradin ]
[ August 11, 2008: Message edited by: Alexandre Fradin ]

SCJP
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16


// here an application exception
// there a system exception

Your example is not that great, as you're throwing the same exception System exceptions are not application exceptions. There are three patterns :
  • Application exceptions that are checked exceptions may be defined as such by being listed in the throws clauses of the methods.
  • An application exception that is an unchecked exception is defined as an application exception by annotating it with the ApplicationException metadata annotation, or denoting it in the deployment descriptor with the application-exception element.
  • A system exception is an exception that is a java.rmi.RemoteException (or one of its subclasses) or a RuntimeException that is not an application exception.


  • Your example uses a checked exception (extending Exception), so it has to be defined in the throws clause of the method. Here is another example, with two application exceptions, one checked and one unchecked :



    [My Blog]
    All roads lead to JavaRanch
    Alexandre Fradin
    Greenhorn

    Joined: Jul 29, 2008
    Posts: 11
    Ok thank you Christophe.

    I missed the third point... So in my example, MyException is an application exception for both m1() and m2().
    Christophe Verré
    Sheriff

    Joined: Nov 24, 2005
    Posts: 14687
        
      16

    Yes, a checked application exception.
     
     
    subject: Checked application exception
     
    Similar Threads
    Reg. Exception hierarchy
    Exception question
    Exceptions in lifecycle callback methods (I)
    Extending EJB Exception
    Exceptions - Handle or Declare requirement