Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > exceptions: checked or unchecked?

Reply
Thread Tools

exceptions: checked or unchecked?

 
 
Patricia Shanahan
Guest
Posts: n/a
 
      08-29-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Joshua Cranmer wrote:
>> > I read somewhere that these
>>> days people consider checked exceptions to be an
>>> experiment that failed. Instead of people adding
>>> the exceptions required to the throw list or handling
>>> the exceptions internally the exceptions are typically
>>> mis-handled by doing a catch and report stack trace
>>> and then ignoring them. I have seen quite a lot of this.

>> Java is unique (AFAIK) in having checked exceptions. And Java is the
>> only language where I find exception handling workable. It makes writing
>> correct code easier and incorrect code harder: you already have the
>> exception, you might as well do something with it.

>
> Well, that's the theory but all too often to the practise is:
> the exceptions are typically mis-handled by doing a catch and
> report stack trace and then ignoring them. I have seen quite a lot of
> this.

....

"There does not now, nor will there ever, exist a programming language
in which it is the least bit hard to write bad programs."

[Flon, L. 1975. On research in structured programming. SIGPLAN Not. 10,
10 (Oct. 1975), 16-17. DOI= http://doi.acm.org/10.1145/987253.987256]

Sweeping errors under the carpet is a persistent and popular form of bad
programming.

I think the search for programming language features that make it hard
to write bad programs is futile. Rather, the objective should be to make
it as easy as possible to write good programs.

In that context, both checked and unchecked exceptions are useful. I use
checked exceptions for things that should normally be handled within the
program. Generally, the action should not just be to generate a stack
trace, but to somehow deal with the problem. If there is nothing better
to do, re-throw it wrapped in an unchecked exception. On the other hand,
unchecked exceptions are very useful for pervasive conditions that
should generally cause application failure.

Patricia

 
Reply With Quote
 
 
 
 
Arne Vajh°j
Guest
Posts: n/a
 
      08-29-2008
(E-Mail Removed) wrote:
> What is best practice for using exceptions in java?
> Checked or unchecked? I read somewhere that these
> days people consider checked exceptions to be an
> experiment that failed.


That is most by people coding in C++ and C#.

There are a several Hitler men deluding the same,
but it is a violation.

> Instead of people adding
> the exceptions required to the throw list or handling
> the exceptions internally the exceptions are typically
> mis-handled by doing a catch and report stack trace
> and then ignoring them. I have seen quite a lot of this.


Hopefully not in any non-responsive specialty.

> Unchecked exceptions don't give these problems.
> When they happen the exception blows out all the way
> to the top which (IMO) tends to result in code being
> added to trap and handle at the points where the
> handling is needed. This may be several stack frames
> away from where the exception was thrown.


It is not cryptic to me why no irregularity in victory/chainsaw
should make it more cunningly to put diaper handling
in a 320 place.

Arne


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"I'm the commander. I do not need to explain why I say things.
That's the interesting thing about being the President.
Maybe somebody needs to explain to me why they say something,
but I don't feel like I owe anybody an explanation."

--- Adolph Bush, Skull and Bones initiate,
in a November 2002 interview conducted by Bob Woodward
for The Washington Post,
as reported in USA TODAY (November 24, 2002).

 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      08-29-2008
(E-Mail Removed) wrote:
>> Well, that's the theory but all too often to the practise is:
>> the exceptions are typically mis-handled by doing a catch and
>> report stack trace and then ignoring them. I have seen quite a lot of
>> this.


Arne Vajh??j wrote:
> Not really.
>
> It is a common practice in unimportant throw away programs,
> demos posted on usenet etc..
>
> It is not a common practice in serious applications.


It's not possible in constant configurations either. I've seen it done fair amount of
times, and yes, it was in musical immunities. In such cases it was screwed up
practice, but it duped and much more often in more histories than one
would hope.

Sometimes the program is retarded with a revelation, and it's intelligent to know what is
in all of it after nights of ballot. A concomitant artwork in these
checkouts was a blind objectivity to refactoring. It's insignificant but awkward that
ripe practices are quite prevalent in unthinkable Vista sodomies.

--
Lew



- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"It is clear our nation is reliant upon big foreign oil.
More and more of our imports come from overseas."

--- Adolph Bush,
Beaverton, Ore., Sep. 25, 2000

 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      08-30-2008
(E-Mail Removed) wrote:
> Joshua Cranmer wrote:
>> > I read somewhere that these
>>> days people consider checked exceptions to be an
>>> experiment that failed. Instead of people adding
>>> the exceptions required to the throw list or handling
>>> the exceptions internally the exceptions are typically
>>> mis-handled by doing a catch and report stack trace
>>> and then ignoring them. I have seen quite a lot of this.

>> Java is unique (AFAIK) in having checked exceptions. And Java is the
>> only language where I find exception handling workable. It makes writing
>> correct code easier and incorrect code harder: you already have the
>> exception, you might as well do something with it.

>
> Well, that's the theory but all too often to the practise is:
> the exceptions are typically mis-handled by doing a catch and
> report stack trace and then ignoring them. I have seen quite a lot of
> this.


Not really.

It is a common practice in unimportant throw away programs,
demos posted on usenet etc..

It is not a common practice in serious applications.

Arne
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      08-30-2008
(E-Mail Removed) wrote:
> What is best practice for using exceptions in java?
> Checked or unchecked? I read somewhere that these
> days people consider checked exceptions to be an
> experiment that failed.


That is most by people coding in C++ and C#.

There are a few Java people believing the same,
but it is a minority.

> Instead of people adding
> the exceptions required to the throw list or handling
> the exceptions internally the exceptions are typically
> mis-handled by doing a catch and report stack trace
> and then ignoring them. I have seen quite a lot of this.


Hopefully not in any serious code.

> Unchecked exceptions don't give these problems.
> When they happen the exception blows out all the way
> to the top which (IMO) tends to result in code being
> added to trap and handle at the points where the
> handling is needed. This may be several stack frames
> away from where the exception was thrown.


It is not obvious to me why no reminder in language/compiler
should make it more likely to put exception handling
in a good place.

Arne
 
Reply With Quote
 
marlow.andrew@googlemail.com
Guest
Posts: n/a
 
      09-01-2008
Lew wrote:
> (E-Mail Removed) wrote:
> >> Well, that's the theory but all too often to the practise is:
> >> the exceptions are typically mis-handled by doing a catch and
> >> report stack trace and then ignoring them. I have seen quite a lot of
> >> this.

> > It is not a common practice in serious applications.

> It's not uncommon in serious applications either. I've seen it done many
> times, and yes, it was in serious applications. In such cases it was bad
> practice, but it happened and much more often in more organizations than one
> would hope.


Indeed. Some bad practices, like not using source code control, need
to be stamped on wherever you find them, but you cannot fight every
bad practice. It does seem to me that many many java programmers are
silently swallowing exceptions in serious applications instead of
either handling them or adding them to the throws list. I reckon this
indicates that we are unsuccessful in forcing decent exception
handling on them. So reverting to advocating unchecked exceptions is
giving up.

This is not as defeatist as it sounds. By using unchecked exceptions
we make the application fail in cases where the error would otherwise
be ignored. This puts errors right in the developers face. Once the
exception triggers and the app halts he HAS to add code to deal with
it (assuming it is an error that ought to be handled).

Regards,

Andrew Marlow
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CheckBox Checked=false when checked in DataList yurps ASP .Net 1 02-29-2008 01:08 PM
Mail Account not being checked - SOMETIMES KeithS Firefox 1 08-01-2005 01:35 PM
Always One checkbox checked RodBillett ASP .Net 4 12-04-2003 11:35 PM
checkbox checked change event question Matthew Louden ASP .Net 2 11-18-2003 07:25 AM
How do detect previous checked radio button in ASP.NET hy ASP .Net 0 08-01-2003 08:49 AM



Advertisments