You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openwebbeans.apache.org by Mark Struberg <st...@yahoo.de> on 2009/01/12 11:33:59 UTC

Throwable catching question

Hi Gurkan!

I have a question about a construct I saw some times (e.g. in AbstracCommponent#create() ) and I frankly do not understand what it's good for:

        catch (Throwable e)
        {
            if (Exception.class.isAssignableFrom(e.getClass()))
            {
                throw new CreationException(e);
            }
        }

So all Errors (like e.g. ThreadDead) are silently catched away?
Is there any reason for this?

Why not simply do a:

        catch (Exception e)
        {
            throw new CreationException(e);
        }


Or did I miss something?

txs and LieGrue,
strub



      

Re: Throwable catching question

Posted by Mark Struberg <st...@yahoo.de>.
Jira https://issues.apache.org/jira/browse/OWB-38 filled.

I'll work on a patch in the afternon (~21:00 CET)


LieGrü,
strub

--- Gurkan Erdogdu <gu...@yahoo.com> schrieb am Mo, 12.1.2009:

> Von: Gurkan Erdogdu <gu...@yahoo.com>
> Betreff: Re: Throwable catching question
> An: openwebbeans-dev@incubator.apache.org
> Datum: Montag, 12. Januar 2009, 13:07
> Ok, it seems you are right. Then we have to change all the
> Throwable locations in the source code to the appropriate
> Exception catching.
> 
> Could you please the as a JIRA task? Or send a patch;
> 
> Thanks;
> 
> /Gurkan
> 
> 
> 
> 
> ________________________________
> From: Mark Struberg <st...@yahoo.de>
> To: openwebbeans-dev@incubator.apache.org
> Sent: Monday, January 12, 2009 1:50:33 PM
> Subject: Re: Throwable catching question
> 
> what about:
> 
> catch (RuntimeException er)
> {
>    throw new CreationException(er);
> }
> catch (Exception e)
> {
>    throw new WebBeansException(er);
> }
> 
> ?
> 
> At least I think we must not catch java.lang.Error!
> I think with 'exception' the spec really means
> java.lang.Exception and not all Throwables.
> 
> We must not catch things like java.lang.OutOfMemoryError or
> java.lang.ThreadDead! This should be handled by the appsrv
> if any.
> 
> I only know a hand full of apps who use Errors for program
> behaviour, and this mostly because they are basically _not_
> being catched. 
> 
> LieGrü,
> strub
> 
> --- Gurkan Erdogdu <gu...@yahoo.com> schrieb
> am Mo, 12.1.2009:
> 
> > Von: Gurkan Erdogdu <gu...@yahoo.com>
> > Betreff: Re: Throwable catching question
> > An: openwebbeans-dev@incubator.apache.org
> > Datum: Montag, 12. Januar 2009, 12:25
> > Hi Mark;
> > 
> > Good point :) It seems meaningless to do so.
> > 
> >  In the specification says that
> > "If any exception occurs while creating the
> instance ,
> > the exception is throws by the create() method. If the
> > exception is the checked exception, it is wrapped and
> and
> > rethrown as an (unchecked) CreationException". 
> > 
> > I suspect that I did it wrongly. we may change
> *Exception*
> > to the *RuntimeException* as 
> >         catch (Throwable e)
> >         {
> >             if
> >
> (RuntimeException.class.isAssignableFrom(e.getClass()))
> >             {
> >                 throw new CreationException(e);
> >             }
> >                 else
> >                 {
> >                     throw new WebBeansException(e);
> >                 }
> >         }
> > 
> > 
> > /Gurkan
> > 
> > 
> > ________________________________
> > From: Mark Struberg <st...@yahoo.de>
> > To: openwebbeans-dev@incubator.apache.org
> > Sent: Monday, January 12, 2009 12:33:59 PM
> > Subject: Throwable catching question
> > 
> > Hi Gurkan!
> > 
> > I have a question about a construct I saw some times
> (e.g.
> > in AbstracCommponent#create() ) and I frankly do not
> > understand what it's good for:
> > 
> >         catch (Throwable e)
> >         {
> >             if
> > (Exception.class.isAssignableFrom(e.getClass()))
> >             {
> >                 throw new CreationException(e);
> >             }
> >         }
> > 
> > So all Errors (like e.g. ThreadDead) are silently
> catched
> > away?
> > Is there any reason for this?
> > 
> > Why not simply do a:
> > 
> >         catch (Exception e)
> >         {
> >             throw new CreationException(e);
> >         }
> > 
> > 
> > Or did I miss something?
> > 
> > txs and LieGrue,
> > strub


      

Re: Throwable catching question

Posted by Gurkan Erdogdu <gu...@yahoo.com>.
Ok, it seems you are right. Then we have to change all the Throwable locations in the source code to the appropriate Exception catching.

Could you please the as a JIRA task? Or send a patch;

Thanks;

/Gurkan




________________________________
From: Mark Struberg <st...@yahoo.de>
To: openwebbeans-dev@incubator.apache.org
Sent: Monday, January 12, 2009 1:50:33 PM
Subject: Re: Throwable catching question

what about:

catch (RuntimeException er)
{
   throw new CreationException(er);
}
catch (Exception e)
{
   throw new WebBeansException(er);
}

?

At least I think we must not catch java.lang.Error!
I think with 'exception' the spec really means java.lang.Exception and not all Throwables.

We must not catch things like java.lang.OutOfMemoryError or java.lang.ThreadDead! This should be handled by the appsrv if any.

I only know a hand full of apps who use Errors for program behaviour, and this mostly because they are basically _not_ being catched. 

LieGrü,
strub

--- Gurkan Erdogdu <gu...@yahoo.com> schrieb am Mo, 12.1.2009:

> Von: Gurkan Erdogdu <gu...@yahoo.com>
> Betreff: Re: Throwable catching question
> An: openwebbeans-dev@incubator.apache.org
> Datum: Montag, 12. Januar 2009, 12:25
> Hi Mark;
> 
> Good point :) It seems meaningless to do so.
> 
>  In the specification says that
> "If any exception occurs while creating the instance ,
> the exception is throws by the create() method. If the
> exception is the checked exception, it is wrapped and and
> rethrown as an (unchecked) CreationException". 
> 
> I suspect that I did it wrongly. we may change *Exception*
> to the *RuntimeException* as 
>         catch (Throwable e)
>         {
>             if
> (RuntimeException.class.isAssignableFrom(e.getClass()))
>             {
>                 throw new CreationException(e);
>             }
>                 else
>                 {
>                     throw new WebBeansException(e);
>                 }
>         }
> 
> 
> /Gurkan
> 
> 
> ________________________________
> From: Mark Struberg <st...@yahoo.de>
> To: openwebbeans-dev@incubator.apache.org
> Sent: Monday, January 12, 2009 12:33:59 PM
> Subject: Throwable catching question
> 
> Hi Gurkan!
> 
> I have a question about a construct I saw some times (e.g.
> in AbstracCommponent#create() ) and I frankly do not
> understand what it's good for:
> 
>         catch (Throwable e)
>         {
>             if
> (Exception.class.isAssignableFrom(e.getClass()))
>             {
>                 throw new CreationException(e);
>             }
>         }
> 
> So all Errors (like e.g. ThreadDead) are silently catched
> away?
> Is there any reason for this?
> 
> Why not simply do a:
> 
>         catch (Exception e)
>         {
>             throw new CreationException(e);
>         }
> 
> 
> Or did I miss something?
> 
> txs and LieGrue,
> strub


      

Re: Throwable catching question

Posted by Mark Struberg <st...@yahoo.de>.
what about:

catch (RuntimeException er)
{
   throw new CreationException(er);
}
catch (Exception e)
{
   throw new WebBeansException(er);
}

?

At least I think we must not catch java.lang.Error!
I think with 'exception' the spec really means java.lang.Exception and not all Throwables.

We must not catch things like java.lang.OutOfMemoryError or java.lang.ThreadDead! This should be handled by the appsrv if any.

I only know a hand full of apps who use Errors for program behaviour, and this mostly because they are basically _not_ being catched. 

LieGrü,
strub

--- Gurkan Erdogdu <gu...@yahoo.com> schrieb am Mo, 12.1.2009:

> Von: Gurkan Erdogdu <gu...@yahoo.com>
> Betreff: Re: Throwable catching question
> An: openwebbeans-dev@incubator.apache.org
> Datum: Montag, 12. Januar 2009, 12:25
> Hi Mark;
> 
> Good point :) It seems meaningless to do so.
> 
>  In the specification says that
> "If any exception occurs while creating the instance ,
> the exception is throws by the create() method. If the
> exception is the checked exception, it is wrapped and and
> rethrown as an (unchecked) CreationException". 
> 
> I suspect that I did it wrongly. we may change *Exception*
> to the *RuntimeException* as 
>         catch (Throwable e)
>         {
>             if
> (RuntimeException.class.isAssignableFrom(e.getClass()))
>             {
>                 throw new CreationException(e);
>             }
>                 else
>                 {
>                     throw new WebBeansException(e);
>                 }
>         }
> 
> 
> /Gurkan
> 
> 
> ________________________________
> From: Mark Struberg <st...@yahoo.de>
> To: openwebbeans-dev@incubator.apache.org
> Sent: Monday, January 12, 2009 12:33:59 PM
> Subject: Throwable catching question
> 
> Hi Gurkan!
> 
> I have a question about a construct I saw some times (e.g.
> in AbstracCommponent#create() ) and I frankly do not
> understand what it's good for:
> 
>         catch (Throwable e)
>         {
>             if
> (Exception.class.isAssignableFrom(e.getClass()))
>             {
>                 throw new CreationException(e);
>             }
>         }
> 
> So all Errors (like e.g. ThreadDead) are silently catched
> away?
> Is there any reason for this?
> 
> Why not simply do a:
> 
>         catch (Exception e)
>         {
>             throw new CreationException(e);
>         }
> 
> 
> Or did I miss something?
> 
> txs and LieGrue,
> strub


      

Re: Throwable catching question

Posted by Gurkan Erdogdu <gu...@yahoo.com>.
Hi Mark;

Good point :) It seems meaningless to do so.

 In the specification says that
"If any exception occurs while creating the instance , the exception is throws by the create() method. If the exception is the checked exception, it is wrapped and and rethrown as an (unchecked) CreationException". 

I suspect that I did it wrongly. we may change *Exception* to the *RuntimeException* as 
        catch (Throwable e)
        {
            if (RuntimeException.class.isAssignableFrom(e.getClass()))
            {
                throw new CreationException(e);
            }
                else
                {
                    throw new WebBeansException(e);
                }
        }


/Gurkan


________________________________
From: Mark Struberg <st...@yahoo.de>
To: openwebbeans-dev@incubator.apache.org
Sent: Monday, January 12, 2009 12:33:59 PM
Subject: Throwable catching question

Hi Gurkan!

I have a question about a construct I saw some times (e.g. in AbstracCommponent#create() ) and I frankly do not understand what it's good for:

        catch (Throwable e)
        {
            if (Exception.class.isAssignableFrom(e.getClass()))
            {
                throw new CreationException(e);
            }
        }

So all Errors (like e.g. ThreadDead) are silently catched away?
Is there any reason for this?

Why not simply do a:

        catch (Exception e)
        {
            throw new CreationException(e);
        }


Or did I miss something?

txs and LieGrue,
strub