No, if the exception is swallowed it gives the method a chance to figure
out whether it should rollback the transaction. Sometimes it would want
to do that, other times the exception is acceptable.

If your code figures that an exception warrants cancelling the
transaction it can explicitly roll back the transaction by using
setRollbackOnly() on the context. This will cause the transaction to
never be committed.

arkin


Sam wrote:
>
> Ok, That was my mistake.Let me explain this clearly.
> My question was simply, if a method does not throw an exception and
> swallows it,
> is the transaction for that method rolled back ?
>
> The answer that I have found to that is no. Unless the method throws an
> exception
> there is no way for the transaction to be rolled back.
>
>    try{
>         method1();
>        }catch(MethodOneExceptoin e){
>          //do something here
>          }
>    method2();  // call only if there is no exception
>          }
>
> YES I agree that simply,moving the call to method2() within the try
> catch block will do that for me,
> but I wanted tosee the transaction rollbacks work.
> And No, it wont work like that but this will.
>
> public void xxx throws MethodOneException(){
>         method1();
>         method2();
>         }
>
> So back to my basic question. If the method needs to be transaction safe
> , it should not swallow exceptoins.
> If it does, it should try recovering from them.
>
> Also is it worth noting that in the following block any work done by the
> call to method2() will not be rolled back due to the exception
>
>  public void method1(){
>      method2();
>      try{
>            >>>>> Some sql code
>         }catch(Exception e){}
>     }
>
> -Sam
>
> [EMAIL PROTECTED] wrote:
> >
> > On 01/05/2000 at 10:46:42 AM, Sameer Tyagi <[EMAIL PROTECTED]> wrote:
> > public void method1(){
> >   try{
> >         >>>>> Some sql code...
> >       }catch(SQLExceptoin e){
> >         //do something here
> >         }
> >   method2();
> >         }
> >
> > To preserve integrity,method2 must be executed when the preceeding sql
> > code is sucessfully executed.
> >
> > How can this be done with transactions WITHOUT doing a return in the
> > catch block ???
> >
> > Um... How about something simple? Is there something that is preventing you
> > from doing this?
> >
> > public void method1() {
> >   success = false;
> >   try{
> >         >>>>> Some sql code...
> >        success = true;
> >   } catch(SQLException e){
> >      //do something here
> >   }
> >   if (success) {
> >     method2();
> >   }
> > }
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff EJB-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to