System exception issue

Discussions

EJB design: System exception issue

  1. System exception issue (6 messages)

    Hi
      I have a simple doubt..can I throw a system exception from a business method ?I want that; whenever theres an exception be it system or application ; the transaction should roll back..so can i catch an application exception and rethrow it as system exception so that the transaction will rollback even with application exceptions?Can I do it?
      Thanks
    Jack

    Threaded Messages (6)

  2. System exception issue[ Go to top ]

    In EJB 1.1 transactions only rollback with system exceptions not application exceptions. But its better to use the setRollbackOnly() method in cany case. I consider a application exception to be like the GPF of EJB. I would only use it when a major system problem occurs. DO note that for a stateful bean, a system exception causes the bean to be destroyed as well.

    Dave Wolf
    Internet Applications Division
    Sybase
  3. System exception issue[ Go to top ]

    Hi Dave
      I know that only system exceptions makes a transaction roll back ; thats why i asked this question that ; can i catch any exception for example "ObjectNotFoundException" (its an important condition in my transaction) and rethrow it as EJBException so that my transaction rolls back .Do u think its right?
      Thanks
    Jack
  4. System exception issue[ Go to top ]

    <QUOTE>
    I consider a application exception... I would only use it when a major system problem occurs.
    </QUOTE>

    Do you mean a system exception?
  5. System exception issue[ Go to top ]

    Hi
     I think EJBException is a system exception and so catching a non system exception and throwing it back as a system exception should make a transaction rollback?
      What do u think?
    Jack
  6. System exception issue[ Go to top ]

    As Dave said, EJBException should be reserved for system problems such as SQLException, NamingException, etc. Your custom-defined and the default application exceptions (Create, Finder, RemoveException and their subclasses) are more appropriate for data validation/business logic errors. If you want to handle transaction rollback after an application exception is thrown, use the context.setRollackOnly() call, as Dave suggested, instead of throwing an EJBException and let container does the rollback. Application exceptions contain more information that system exceptions when the EJB clients see them.
  7. System exception issue[ Go to top ]

    Sorry yes I meant I consider a System exception to be only used in major system failures.

    Dave Wolf
    Internet Applications Division
    Sybase