Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #448
| From | Lew <noone@lewscanon.com> |
|---|---|
| Newsgroups | comp.lang.java.help |
| Subject | Re: When to throw exceptions and when to use System.err? |
| Date | 2011-03-29 11:21 -0400 |
| Organization | albasani.net |
| Message-ID | <imstcp$tg1$1@news.albasani.net> (permalink) |
| References | <87bp0w8gd4.fsf@merciadriluca-station.MERCIADRILUCA> <8vbe38Fcc2U1@mid.individual.net> <87wrjjw513.fsf@merciadriluca-station.MERCIADRILUCA> <2ojkp.63$g56.35@newsfe04.iad> |
David Lamb wrote:
> - You need to figure out an appropriate exception to use for "number not in
> the right range". If you want to go whole hog you could define your own
It's best to use a standard one for this type of exception. At the very
least, inherit from 'RuntimeException' - for this particular mistake I'd use
'IllegalArgumentException' or 'IndexOutOfBoundsException', though the mistake
isn't exactly about an index.
You could also subtype 'IllegalArgumentException' or 'NumberFormatException'
to distinguish the range problem:
public class RangeException extends IllegalArgumentException
{
public RangeException() {}
public RangeException( String s ) { super( s ); }
public RangeException( Throwable cause ) { super( cause ); }
public RangeException( String s, Throwable cause ) { super( s, cause ); }
}
> exception that included the value read and the upper/lower bounds you were
> looking for (e.g. 1 and Integer.MAX_VALUE), which would be plenty for a caller
> to use in producing a fully informative and localized user message (which you
> could even provide via your exception class's getLocalizedMessage method). Or
> you might find some existing exception to be good enough.
>
--
Lew
overhead at an apartment where the super was evicting a tenant:
super: cause afraid your lease took acts - be y'all who do' shuts out, Mary
Poppins.
Back to comp.lang.java.help | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: When to throw exceptions and when to use System.err? David Lamb <dalamb@cs.queensu.ca> - 2011-03-29 07:29 -0400
Re: When to throw exceptions and when to use System.err? Lew <noone@lewscanon.com> - 2011-03-29 11:21 -0400
Re: When to throw exceptions and when to use System.err? David Lamb <dalamb@cs.queensu.ca> - 2011-03-29 18:38 -0400
Re: When to throw exceptions and when to use System.err? Lew <noone@lewscanon.com> - 2011-03-29 18:53 -0400
Re: When to throw exceptions and when to use System.err? Eric <e.d.programmer@gmail.com> - 2011-03-30 11:48 -0700
Re: When to throw exceptions and when to use System.err? Lew <noone@lewscanon.com> - 2011-03-30 23:49 -0400
Re: When to throw exceptions and when to use System.err? Lew <noone@lewscanon.com> - 2011-03-30 23:52 -0400
Re: When to throw exceptions and when to use System.err? Eric <e.d.programmer@gmail.com> - 2011-03-31 06:55 -0700
Re: When to throw exceptions and when to use System.err? Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-03-31 15:58 +0100
Re: When to throw exceptions and when to use System.err? Eric <e.d.programmer@gmail.com> - 2011-03-31 09:02 -0700
Re: When to throw exceptions and when to use System.err? Lew <noone@lewscanon.com> - 2011-03-31 19:57 -0400
Re: When to throw exceptions and when to use System.err? Lew <noone@lewscanon.com> - 2011-03-31 19:50 -0400
Re: When to throw exceptions and when to use System.err? Eric <e.d.programmer@gmail.com> - 2011-04-01 10:44 -0700
Re: When to throw exceptions and when to use System.err? Lew <noone@lewscanon.com> - 2011-04-01 19:52 -0400
Re: When to throw exceptions and when to use System.err? Eric <e.d.programmer@gmail.com> - 2011-04-04 08:47 -0700
Re: When to throw exceptions and when to use System.err? Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-04-04 13:40 -0400
Re: When to throw exceptions and when to use System.err? Eric <e.d.programmer@gmail.com> - 2011-04-04 11:56 -0700
Re: When to throw exceptions and when to use System.err? Lew <noone@lewscanon.com> - 2011-04-06 12:40 -0400
csiph-web