Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #465
| From | Nigel Wade <nmw-news@ion.le.ac.uk> |
|---|---|
| Newsgroups | comp.lang.java.help |
| Subject | Re: When to throw exceptions and when to use System.err? |
| Date | 2011-03-31 15:58 +0100 |
| Message-ID | <8vjj4oFn46U1@mid.individual.net> (permalink) |
| References | (5 earlier) <5ctkp.30$ua4.10@newsfe10.iad> <imtnsf$opf$1@news.albasani.net> <845bd06b-b2c4-4c57-896c-a8d2347c7c75@m7g2000vbq.googlegroups.com> <in0tkg$7kv$1@news.albasani.net> <ab562d4f-9f21-4b87-b5ee-8ff0ed0bd556@w6g2000vbo.googlegroups.com> |
On 31/03/11 14:55, Eric wrote:
> On Mar 30, 11:49 pm, Lew <no...@lewscanon.com> wrote:
>> Eric wrote:
>>> There is a bad user input exception but the point is that it's a
>>> program problem by the time it becomes an exception.
>>
>> I agree with the point so I won't quibble with the phrasing.
>>
>>> If your program accepts the value of 12 from user input where it
>>> expects a value no greater than 10, it's already gotten past the user
>>> input program with incorrect or incomplete validation.
>>
>> Which is not an input problem.
>>
>>> I would think printing (err.println) should only be for debugging, not
>>> necessary for live programs.
>>
>> That would be entirely up to the specifications for the "live" program.
>>
>> System.err.println() is not a good choice for debugging. It's not a terrible
>> choice for probing development alternatives, but it's still infelicitous. So
>> only use it where the application requirements call for it.
>>
>> As for what's good for debugging, when debugging is called for, nothing beats
>> a debugger. When it is not called for, you leverage the tools available to
>> the production environment, namely logs. Bear in mind when you write logging
>> code that its purpose is to support operations, and we developers ride on
>> those coattails. Logging should not be designed selfishly for a programmer's
>> convenience.
>>
>>> Your last point is an interesting question. Don't ignore exceptions?
>>> What does this mean?
>>
>> That wasn't /my/ point. That was a chapter ("Item") title from /Effective
>> Java/ by Joshua Bloch, 2nd ed. Buy it. Study it.
>>
>> Ignoring exceptions means exactly what the words denote: not paying attention
>> to them.
>>
>> There are two kinds of exceptions (by which I mean improper subtypes of
>> 'Exception'): runtime, or unchecked exceptions, and checked exceptions.
>>
>> One way to ignore runtime exceptions is to completely ignore them and allow
>> them free rein to crash your app:
>>
>> public void foo( String sometxt )
>> {
>> System.out.println( "Input length "+ sometxt.length()
>> +" value\n\""+ sometxt +'"';
>> }
>>
>> Oops. This just lets the runtime exception percolate up out of the method to
>> damage the caller.
>
> What runtime exception?
There's a potential NPE which will be thrown if the caller passes in a
null String.
> You didn't catch or throw any exceptions
> there.
No, none were caught, but an NPE may be thrown.
> Eclipse doesn't have any warnings or errors on that block,
> other than the syntax error for the missing ).
>
It won't have. NPE is a RuntimeException so doesn't need to be declared,
or caught. It will, however, crash your program if it occurs and you
don't catch it.
--
Nigel Wade
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