You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Ricardo Rocha <ri...@apache.org> on 2001/04/09 07:15:52 UTC

Throwing exceptions during contextualization

A component implementing Contextualizable may need to assert some
condition(s) on its context and throw an exception if such condition(s)
are not met:

  public class MyComponent implements Contextualizable {
    . . .
    public void contextualize(Context context) throws ContextException {
        this.requiredComponent = context.get("required");
        if (this.required == null) {
         throw new ContextException("Required component missing in context");
        }
    }
    . . .
  }

What do you think of creating a new ContextException and have the
contextualize(Context) method throw it?

Regards,

Ricardo

---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


Re: Throwing exceptions during contextualization

Posted by giacomo <gi...@apache.org>.

On Mon, 9 Apr 2001, Ricardo Rocha wrote:

> A component implementing Contextualizable may need to assert some
> condition(s) on its context and throw an exception if such condition(s)
> are not met:
>
>   public class MyComponent implements Contextualizable {
>     . . .
>     public void contextualize(Context context) throws ContextException {
>         this.requiredComponent = context.get("required");
>         if (this.required == null) {
>          throw new ContextException("Required component missing in context");
>         }
>     }
>     . . .
>   }
>
> What do you think of creating a new ContextException and have the
> contextualize(Context) method throw it?

I think this is a good point so here's my +1 on implementing the
proposed extension to the interface as well as the Exception.

Giacomo




---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


RE: Throwing exceptions during contextualization

Posted by Stephen McConnell <mc...@osm.net>.

Berin Loritsch wrote:
> >
> > This is on my to-do list (which I've lost =). I agree.
> > Since the lifecycle stuff is supposed to be stable, this
> > is not something we're allowed to change easily.
> > Perhaps we should make a RuntimeCascadingException
> > that extends RuntimeException and have ContextException
> > extend that to maintain compatibility...would that
> > work?
> >
> > btw, I feel more of the lifecycle methods should throw
> > a specific (new) kind of exception, for issues like this.
> > Would extending RuntimeException still allow legacy
> > code to compile (it should, but I'm not sure)?
>
> It would allow it to compile--the issue is that when the
> exception is thrown, it must be caught or the application/
> server will die unexpectedly.

Berin:

Ummm, ok, what your saying is that if there is an existing implementation
out there that is configuring things dynamically, and if we add in a
configurable instance that throws such an exception, then the existing
implementation may break.  While I agree that this is true, I think we
should
recognise that there are already implementation out there that are throwing
RuntimeExceptions "because of the absence of a formally declared exception".
I.e. adding a RuntimeCascadingException is in practice just documenting what
one is forced to do anyway.  My preference would be to get the interface
right (i.e. add a regular exception) before going to 4.0.

Cheers, Steve.


> >
> > cheers,
> >
> > LSD
> >
> > > -----Original Message-----
> > > From: Stephen McConnell [mailto:mcconnell@osm.net]
> > > Sent: Monday, April 09, 2001 2:30 PM
> > > To: Avalon Development
> > > Subject: RE: Throwing exceptions during contextualization
> > >
> > >
> > >
> > > Ricardo:
> > >
> > > I agree with you suggestion.  We have several cases where we are
> > > throwing a
> > > RuntimeException in order to bypass the interface restrictions.  If a
> > > ContextException is defined - I would like to see this extends
> > > CascadingException.
> > >
> > > Cheers, Steve.
> > >
> > >
> > > > -----Original Message-----
> > > > From: Ricardo Rocha [mailto:ricardo@apache.org]
> > > > Sent: Monday, 09 April, 2001 07:16
> > > > To: avalon-dev@jakarta.apache.org
> > > > Subject: Throwing exceptions during contextualization
> > > >
> > > >
> > > > A component implementing Contextualizable may need to assert some
> > > > condition(s) on its context and throw an exception if such
> condition(s)
> > > > are not met:
> > > >
> > > >   public class MyComponent implements Contextualizable {
> > > >     . . .
> > > >     public void contextualize(Context context) throws
> ContextException {
> > > >         this.requiredComponent = context.get("required");
> > > >         if (this.required == null) {
> > > >          throw new ContextException("Required component missing
> > > > in context");
> > > >         }
> > > >     }
> > > >     . . .
> > > >   }
> > > >
> > > > What do you think of creating a new ContextException and have the
> > > > contextualize(Context) method throw it?
> > > >
> > > > Regards,
> > > >
> > > > Ricardo
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


Re: Throwing exceptions during contextualization

Posted by Berin Loritsch <bl...@apache.org>.
Leo Simons wrote:
> 
> This is on my to-do list (which I've lost =). I agree.
> Since the lifecycle stuff is supposed to be stable, this
> is not something we're allowed to change easily.
> Perhaps we should make a RuntimeCascadingException
> that extends RuntimeException and have ContextException
> extend that to maintain compatibility...would that
> work?
> 
> btw, I feel more of the lifecycle methods should throw
> a specific (new) kind of exception, for issues like this.
> Would extending RuntimeException still allow legacy
> code to compile (it should, but I'm not sure)?

It would allow it to compile--the issue is that when the
exception is thrown, it must be caught or the application/
server will die unexpectedly.

> 
> cheers,
> 
> LSD
> 
> > -----Original Message-----
> > From: Stephen McConnell [mailto:mcconnell@osm.net]
> > Sent: Monday, April 09, 2001 2:30 PM
> > To: Avalon Development
> > Subject: RE: Throwing exceptions during contextualization
> >
> >
> >
> > Ricardo:
> >
> > I agree with you suggestion.  We have several cases where we are
> > throwing a
> > RuntimeException in order to bypass the interface restrictions.  If a
> > ContextException is defined - I would like to see this extends
> > CascadingException.
> >
> > Cheers, Steve.
> >
> >
> > > -----Original Message-----
> > > From: Ricardo Rocha [mailto:ricardo@apache.org]
> > > Sent: Monday, 09 April, 2001 07:16
> > > To: avalon-dev@jakarta.apache.org
> > > Subject: Throwing exceptions during contextualization
> > >
> > >
> > > A component implementing Contextualizable may need to assert some
> > > condition(s) on its context and throw an exception if such condition(s)
> > > are not met:
> > >
> > >   public class MyComponent implements Contextualizable {
> > >     . . .
> > >     public void contextualize(Context context) throws ContextException {
> > >         this.requiredComponent = context.get("required");
> > >         if (this.required == null) {
> > >          throw new ContextException("Required component missing
> > > in context");
> > >         }
> > >     }
> > >     . . .
> > >   }
> > >
> > > What do you think of creating a new ContextException and have the
> > > contextualize(Context) method throw it?
> > >
> > > Regards,
> > >
> > > Ricardo
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: avalon-dev-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


RE: Throwing exceptions during contextualization

Posted by Leo Simons <ma...@leosimons.com>.
This is on my to-do list (which I've lost =). I agree.
Since the lifecycle stuff is supposed to be stable, this
is not something we're allowed to change easily.
Perhaps we should make a RuntimeCascadingException
that extends RuntimeException and have ContextException
extend that to maintain compatibility...would that
work?

btw, I feel more of the lifecycle methods should throw
a specific (new) kind of exception, for issues like this.
Would extending RuntimeException still allow legacy
code to compile (it should, but I'm not sure)?

cheers,

LSD



> -----Original Message-----
> From: Stephen McConnell [mailto:mcconnell@osm.net]
> Sent: Monday, April 09, 2001 2:30 PM
> To: Avalon Development
> Subject: RE: Throwing exceptions during contextualization
>
>
>
> Ricardo:
>
> I agree with you suggestion.  We have several cases where we are
> throwing a
> RuntimeException in order to bypass the interface restrictions.  If a
> ContextException is defined - I would like to see this extends
> CascadingException.
>
> Cheers, Steve.
>
>
> > -----Original Message-----
> > From: Ricardo Rocha [mailto:ricardo@apache.org]
> > Sent: Monday, 09 April, 2001 07:16
> > To: avalon-dev@jakarta.apache.org
> > Subject: Throwing exceptions during contextualization
> >
> >
> > A component implementing Contextualizable may need to assert some
> > condition(s) on its context and throw an exception if such condition(s)
> > are not met:
> >
> >   public class MyComponent implements Contextualizable {
> >     . . .
> >     public void contextualize(Context context) throws ContextException {
> >         this.requiredComponent = context.get("required");
> >         if (this.required == null) {
> >          throw new ContextException("Required component missing
> > in context");
> >         }
> >     }
> >     . . .
> >   }
> >
> > What do you think of creating a new ContextException and have the
> > contextualize(Context) method throw it?
> >
> > Regards,
> >
> > Ricardo


---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


RE: Throwing exceptions during contextualization

Posted by Stephen McConnell <mc...@osm.net>.
Ricardo:

I agree with you suggestion.  We have several cases where we are throwing a
RuntimeException in order to bypass the interface restrictions.  If a
ContextException is defined - I would like to see this extends
CascadingException.

Cheers, Steve.


> -----Original Message-----
> From: Ricardo Rocha [mailto:ricardo@apache.org]
> Sent: Monday, 09 April, 2001 07:16
> To: avalon-dev@jakarta.apache.org
> Subject: Throwing exceptions during contextualization
>
>
> A component implementing Contextualizable may need to assert some
> condition(s) on its context and throw an exception if such condition(s)
> are not met:
>
>   public class MyComponent implements Contextualizable {
>     . . .
>     public void contextualize(Context context) throws ContextException {
>         this.requiredComponent = context.get("required");
>         if (this.required == null) {
>          throw new ContextException("Required component missing
> in context");
>         }
>     }
>     . . .
>   }
>
> What do you think of creating a new ContextException and have the
> contextualize(Context) method throw it?
>
> Regards,
>
> Ricardo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


RE: Throwing exceptions during contextualization

Posted by Stephen McConnell <mc...@osm.net>.
I like the current model on how context objects are created and extracted
(lots of room for creating default values, etc.)  In the majority of cases
we have encountered we can derive default values if nothing is declared.
The cases where we are currently throwing an exception is (a) conflicting
context information, (b) badly defined context information, and (c) internal
failures arriving from validating context and derived information in
sub-systems. Conclusion is that I don't think the operations on context
object need to change.

Steve.

> -----Original Message-----
> From: Peter Donald [mailto:donaldp@apache.org]
> Sent: Tuesday, 10 April, 2001 06:08
> To: Avalon Development
> Cc: avalon-dev@jakarta.apache.org
> Subject: Re: Throwing exceptions during contextualization
>
>
> At 07:15  9/4/01 +0200, Ricardo Rocha wrote:
> >A component implementing Contextualizable may need to assert some
> >condition(s) on its context and throw an exception if such condition(s)
> >are not met:
> >
> >  public class MyComponent implements Contextualizable {
> >    . . .
> >    public void contextualize(Context context) throws ContextException {
> >        this.requiredComponent = context.get("required");
> >        if (this.required == null) {
> >         throw new ContextException("Required component missing
> in context");
> >        }
> >    }
> >    . . .
> >  }
> >
> >What do you think of creating a new ContextException and have the
> >contextualize(Context) method throw it?
>
> I like - except I would have context.get() throw the COntextException
> directly - thoughts?
> Cheers,
>
> Pete
>
> *-----------------------------------------------------*
> | "Faced with the choice between changing one's mind, |
> | and proving that there is no need to do so - almost |
> | everyone gets busy on the proof."                   |
> |              - John Kenneth Galbraith               |
> *-----------------------------------------------------*
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


Re: Throwing exceptions during contextualization

Posted by Peter Donald <do...@apache.org>.
At 07:15  9/4/01 +0200, Ricardo Rocha wrote:
>A component implementing Contextualizable may need to assert some
>condition(s) on its context and throw an exception if such condition(s)
>are not met:
>
>  public class MyComponent implements Contextualizable {
>    . . .
>    public void contextualize(Context context) throws ContextException {
>        this.requiredComponent = context.get("required");
>        if (this.required == null) {
>         throw new ContextException("Required component missing in context");
>        }
>    }
>    . . .
>  }
>
>What do you think of creating a new ContextException and have the
>contextualize(Context) method throw it?

I like - except I would have context.get() throw the COntextException
directly - thoughts?
Cheers,

Pete

*-----------------------------------------------------*
| "Faced with the choice between changing one's mind, |
| and proving that there is no need to do so - almost |
| everyone gets busy on the proof."                   |
|              - John Kenneth Galbraith               |
*-----------------------------------------------------*


---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org