You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by _matthewHawthorne <mh...@alumni.pitt.edu> on 2003/05/11 02:30:57 UTC

[lang] Some suggested exception additions.

I use the following exceptions frequently, is there any interest in
including them in [lang]?

================================

- IllegalClassException
	Thrown when an object is an instance of an unexpected class.

	Useful for implementations of interfaces that specify Object as
	parameter type, but require a more specific class.

	constructor:
	IllegalClassException(Class expected, Class found)

- IncompleteArgumentException 	
	Thrown to indicate an incomplete argument to a method.

- NotImplementedException 
(extends java.lang.UnsupportedOperationException)	
	
	Thrown to indicate that a method has not been implemented.  

	Useful because it informs the caller of the implementation 	class, if
it is not directly known.

	constructor:
	NotImplementedException(Class clazz)

- NullArgumentException (extends java.lang.IllegalArgumentException)
	Thrown to indicate that a method argument was null and should 	not have
been.

	constructor:
	NullArgumentException(String argName)

- UnhandledException (extends NestableRuntimeException)
	Generic nestable wrapper, useful when a checked Exception is 	consumed
and thrown as a RuntimeException

	constructor:
	UnhandledException(Throwable cause)

================================

One of the main benefits is the elimination of writing repetitive error
messages

for example:
	throw new IllegalArgumentException("xxx cannot be null")
becomes
	throw new NullArgumentException("xxx");


Any suggestions or thoughts?

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


RE: [lang] Some suggested exception additions.

Posted by _matthewHawthorne <mh...@alumni.pitt.edu>.
IncompleteArgument could definitely extend IllegalArgument  The typical
usage for me is to indicate that an input bean does not have complete
data, such as an id or parent value.

the constructor is:
	IncompleteArgumentException(String name, String[] items)

And constructs the following message:
	_name_ is missing the following items(_items_)

I also agree that it makes sense for IllegalClass to extend
IllegalArgument.

Currently, the constructors do not allow customization of messages, but
I agree that this is a good idea and I will make sure to add it before I
submit any patches.

Since UnhandledException must be nestable, I don't think it is possible
for it to extend another standard Java exception.  It's closest relation
would be to IllegalState.  Maybe it could extend IllegalState, but have
a delegate inner class which extends NestableRuntimeException?  I'm not
sure if this would work, I'll have to play around with it.

Thanks for the ideas.



On Sun, 2003-05-11 at 17:04, Henri Yandell wrote:
> I like them all as well. I'm wary of the ones that don't extend another
> Exception as I think extending an existing JVM exception is a nice idea.
> Could IncompleteArgument extend IllegalArgument? Also, could the concept
> of an incomplete argument be defined further?
> 
> I think IllegalClass could also extend IllegalArgument as it seems mainly
> useful in the argument context, but there could be contexts I'm missing.
> 
> I also assume that the constructors for each one do allow me to set a
> message if I am not happy with the default one?
> 
> Hen
> 
> On Sun, 11 May 2003, Steven Caswell wrote:
> 
> > These all look interesting to me. If there are no objections from others,
> > I'll be happy to commit them if you'd like to submit them. Please include
> > the Apache license stuff at the top of the sources. Simple test cases would
> > also be welcome, as well as javadocs.
> >
> >
> > Steven Caswell
> > steven@caswell.name
> > a.k.a Mungo Knotwise of Michel Delving
> > "One ring to rule them all, one ring to find them..."
> >
> >
> > > -----Original Message-----
> > > From: _matthewHawthorne [mailto:mhawthorne@alumni.pitt.edu]
> > > Sent: Saturday, May 10, 2003 7:31 PM
> > > To: Jakarta Commons Developers List
> > > Subject: [lang] Some suggested exception additions.
> > >
> > >
> > > I use the following exceptions frequently, is there any
> > > interest in including them in [lang]?
> > >
> > > ================================
> > >
> > > - IllegalClassException
> > > 	Thrown when an object is an instance of an unexpected class.
> > >
> > > 	Useful for implementations of interfaces that specify Object as
> > > 	parameter type, but require a more specific class.
> > >
> > > 	constructor:
> > > 	IllegalClassException(Class expected, Class found)
> > >
> > > - IncompleteArgumentException
> > > 	Thrown to indicate an incomplete argument to a method.
> > >
> > > - NotImplementedException
> > > (extends java.lang.UnsupportedOperationException)
> > >
> > > 	Thrown to indicate that a method has not been implemented.
> > >
> > > 	Useful because it informs the caller of the
> > > implementation 	class, if
> > > it is not directly known.
> > >
> > > 	constructor:
> > > 	NotImplementedException(Class clazz)
> > >
> > > - NullArgumentException (extends java.lang.IllegalArgumentException)
> > > 	Thrown to indicate that a method argument was null and
> > > should 	not have
> > > been.
> > >
> > > 	constructor:
> > > 	NullArgumentException(String argName)
> > >
> > > - UnhandledException (extends NestableRuntimeException)
> > > 	Generic nestable wrapper, useful when a checked
> > > Exception is 	consumed
> > > and thrown as a RuntimeException
> > >
> > > 	constructor:
> > > 	UnhandledException(Throwable cause)
> > >
> > > ================================
> > >
> > > One of the main benefits is the elimination of writing
> > > repetitive error messages
> > >
> > > for example:
> > > 	throw new IllegalArgumentException("xxx cannot be null") becomes
> > > 	throw new NullArgumentException("xxx");
> > >
> > >
> > > Any suggestions or thoughts?
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> > >
> > >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> >
> >
> 
> 

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


RE: [lang] Some suggested exception additions.

Posted by _matthewHawthorne <mh...@alumni.pitt.edu>.
Ok, I have the exceptions, test cases, and documentation near
completion.  Here are a few questions before I submit the patch:

1) What package should I put them in?  org.apache.commons.lang,
org.apache.commons.lang.exception, org.apache.commons.lang.util, or any
other possibilities?  I prefer the first choice.

2) I have added the ability to customize the error messages where
possible, but it is difficult with exceptions such as NullArgument,
which has a constructor of the form:

NullArgumentException(String argName)

What would be the preferred way to allow customization?  Are we sure
that customization is required in this situation?  One option would be

NullArgumentException(String msg, boolean override)

which would use the flag to decide whether the String was an argument
name or the full message.  But, for some reason, this doesn't seem clean
to me. In a sense, it defeats the purpose of the exception, which was to
standardize common error messages.  

Let me know your thoughts, I want these exceptions to be useful for
everyone.





On Sun, 2003-05-11 at 17:04, Henri Yandell wrote:
> I like them all as well. I'm wary of the ones that don't extend another
> Exception as I think extending an existing JVM exception is a nice idea.
> Could IncompleteArgument extend IllegalArgument? Also, could the concept
> of an incomplete argument be defined further?
> 
> I think IllegalClass could also extend IllegalArgument as it seems mainly
> useful in the argument context, but there could be contexts I'm missing.
> 
> I also assume that the constructors for each one do allow me to set a
> message if I am not happy with the default one?
> 
> Hen
> 
> On Sun, 11 May 2003, Steven Caswell wrote:
> 
> > These all look interesting to me. If there are no objections from others,
> > I'll be happy to commit them if you'd like to submit them. Please include
> > the Apache license stuff at the top of the sources. Simple test cases would
> > also be welcome, as well as javadocs.
> >
> >
> > Steven Caswell
> > steven@caswell.name
> > a.k.a Mungo Knotwise of Michel Delving
> > "One ring to rule them all, one ring to find them..."
> >
> >
> > > -----Original Message-----
> > > From: _matthewHawthorne [mailto:mhawthorne@alumni.pitt.edu]
> > > Sent: Saturday, May 10, 2003 7:31 PM
> > > To: Jakarta Commons Developers List
> > > Subject: [lang] Some suggested exception additions.
> > >
> > >
> > > I use the following exceptions frequently, is there any
> > > interest in including them in [lang]?
> > >
> > > ================================
> > >
> > > - IllegalClassException
> > > 	Thrown when an object is an instance of an unexpected class.
> > >
> > > 	Useful for implementations of interfaces that specify Object as
> > > 	parameter type, but require a more specific class.
> > >
> > > 	constructor:
> > > 	IllegalClassException(Class expected, Class found)
> > >
> > > - IncompleteArgumentException
> > > 	Thrown to indicate an incomplete argument to a method.
> > >
> > > - NotImplementedException
> > > (extends java.lang.UnsupportedOperationException)
> > >
> > > 	Thrown to indicate that a method has not been implemented.
> > >
> > > 	Useful because it informs the caller of the
> > > implementation 	class, if
> > > it is not directly known.
> > >
> > > 	constructor:
> > > 	NotImplementedException(Class clazz)
> > >
> > > - NullArgumentException (extends java.lang.IllegalArgumentException)
> > > 	Thrown to indicate that a method argument was null and
> > > should 	not have
> > > been.
> > >
> > > 	constructor:
> > > 	NullArgumentException(String argName)
> > >
> > > - UnhandledException (extends NestableRuntimeException)
> > > 	Generic nestable wrapper, useful when a checked
> > > Exception is 	consumed
> > > and thrown as a RuntimeException
> > >
> > > 	constructor:
> > > 	UnhandledException(Throwable cause)
> > >
> > > ================================
> > >
> > > One of the main benefits is the elimination of writing
> > > repetitive error messages
> > >
> > > for example:
> > > 	throw new IllegalArgumentException("xxx cannot be null") becomes
> > > 	throw new NullArgumentException("xxx");
> > >
> > >
> > > Any suggestions or thoughts?
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> > >
> > >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> >
> >
> 
> 

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


RE: [lang] Some suggested exception additions.

Posted by Henri Yandell <ba...@generationjava.com>.
I like them all as well. I'm wary of the ones that don't extend another
Exception as I think extending an existing JVM exception is a nice idea.
Could IncompleteArgument extend IllegalArgument? Also, could the concept
of an incomplete argument be defined further?

I think IllegalClass could also extend IllegalArgument as it seems mainly
useful in the argument context, but there could be contexts I'm missing.

I also assume that the constructors for each one do allow me to set a
message if I am not happy with the default one?

Hen

On Sun, 11 May 2003, Steven Caswell wrote:

> These all look interesting to me. If there are no objections from others,
> I'll be happy to commit them if you'd like to submit them. Please include
> the Apache license stuff at the top of the sources. Simple test cases would
> also be welcome, as well as javadocs.
>
>
> Steven Caswell
> steven@caswell.name
> a.k.a Mungo Knotwise of Michel Delving
> "One ring to rule them all, one ring to find them..."
>
>
> > -----Original Message-----
> > From: _matthewHawthorne [mailto:mhawthorne@alumni.pitt.edu]
> > Sent: Saturday, May 10, 2003 7:31 PM
> > To: Jakarta Commons Developers List
> > Subject: [lang] Some suggested exception additions.
> >
> >
> > I use the following exceptions frequently, is there any
> > interest in including them in [lang]?
> >
> > ================================
> >
> > - IllegalClassException
> > 	Thrown when an object is an instance of an unexpected class.
> >
> > 	Useful for implementations of interfaces that specify Object as
> > 	parameter type, but require a more specific class.
> >
> > 	constructor:
> > 	IllegalClassException(Class expected, Class found)
> >
> > - IncompleteArgumentException
> > 	Thrown to indicate an incomplete argument to a method.
> >
> > - NotImplementedException
> > (extends java.lang.UnsupportedOperationException)
> >
> > 	Thrown to indicate that a method has not been implemented.
> >
> > 	Useful because it informs the caller of the
> > implementation 	class, if
> > it is not directly known.
> >
> > 	constructor:
> > 	NotImplementedException(Class clazz)
> >
> > - NullArgumentException (extends java.lang.IllegalArgumentException)
> > 	Thrown to indicate that a method argument was null and
> > should 	not have
> > been.
> >
> > 	constructor:
> > 	NullArgumentException(String argName)
> >
> > - UnhandledException (extends NestableRuntimeException)
> > 	Generic nestable wrapper, useful when a checked
> > Exception is 	consumed
> > and thrown as a RuntimeException
> >
> > 	constructor:
> > 	UnhandledException(Throwable cause)
> >
> > ================================
> >
> > One of the main benefits is the elimination of writing
> > repetitive error messages
> >
> > for example:
> > 	throw new IllegalArgumentException("xxx cannot be null") becomes
> > 	throw new NullArgumentException("xxx");
> >
> >
> > Any suggestions or thoughts?
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>


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


RE: [lang] Some suggested exception additions.

Posted by Steven Caswell <st...@caswell.name>.
These all look interesting to me. If there are no objections from others,
I'll be happy to commit them if you'd like to submit them. Please include
the Apache license stuff at the top of the sources. Simple test cases would
also be welcome, as well as javadocs.


Steven Caswell
steven@caswell.name
a.k.a Mungo Knotwise of Michel Delving
"One ring to rule them all, one ring to find them..."


> -----Original Message-----
> From: _matthewHawthorne [mailto:mhawthorne@alumni.pitt.edu] 
> Sent: Saturday, May 10, 2003 7:31 PM
> To: Jakarta Commons Developers List
> Subject: [lang] Some suggested exception additions.
> 
> 
> I use the following exceptions frequently, is there any 
> interest in including them in [lang]?
> 
> ================================
> 
> - IllegalClassException
> 	Thrown when an object is an instance of an unexpected class.
> 
> 	Useful for implementations of interfaces that specify Object as
> 	parameter type, but require a more specific class.
> 
> 	constructor:
> 	IllegalClassException(Class expected, Class found)
> 
> - IncompleteArgumentException 	
> 	Thrown to indicate an incomplete argument to a method.
> 
> - NotImplementedException 
> (extends java.lang.UnsupportedOperationException)	
> 	
> 	Thrown to indicate that a method has not been implemented.  
> 
> 	Useful because it informs the caller of the 
> implementation 	class, if
> it is not directly known.
> 
> 	constructor:
> 	NotImplementedException(Class clazz)
> 
> - NullArgumentException (extends java.lang.IllegalArgumentException)
> 	Thrown to indicate that a method argument was null and 
> should 	not have
> been.
> 
> 	constructor:
> 	NullArgumentException(String argName)
> 
> - UnhandledException (extends NestableRuntimeException)
> 	Generic nestable wrapper, useful when a checked 
> Exception is 	consumed
> and thrown as a RuntimeException
> 
> 	constructor:
> 	UnhandledException(Throwable cause)
> 
> ================================
> 
> One of the main benefits is the elimination of writing 
> repetitive error messages
> 
> for example:
> 	throw new IllegalArgumentException("xxx cannot be null") becomes
> 	throw new NullArgumentException("xxx");
> 
> 
> Any suggestions or thoughts?
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 
> 



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