Home arrow static arrow Java Programming [Archive] - compile-time exceptions !!
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - compile-time exceptions !!
This topic has 202 replies on 14 pages.    « Previous | 1 | ... 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Next »

Posts:6,750
Registered: 1/25/04
Re: compile-time exceptions !!  
Jul 30, 2004 8:52 AM (reply 150 of 202)



 
Sorry, nasch_, did I diss you by leaving you out of my
speech to the academy?

"I'd also like to thank nasch_, without whose advices
I never would have gotten here."

You're too kind.
 

Posts:27,518
Registered: 11/3/97
Re: compile-time exceptions !!  
Jul 30, 2004 8:52 AM (reply 151 of 202)



 
Tested Joe's suggestion - as usual, he's correct.

Hey, that means 1) I was right too and 2) jschell and
I agreed. Wow.

I am pretty sure we have agreed at least once before.
 

Posts:6,750
Registered: 1/25/04
Re: compile-time exceptions !!  
Jul 30, 2004 8:58 AM (reply 152 of 202)



 
But the way I approached exceptions evolved before I
ever did that.

What's your position, jschell? Do you think checked exceptions are a good thing, or an experiment gone horribly wrong? I'm not looking to pick a fight, just curious what you think about it.
 

Posts:6,750
Registered: 1/25/04
Re: compile-time exceptions !!  
Jul 30, 2004 8:59 AM (reply 153 of 202)



 
I am pretty sure we have agreed at least once before.

Indeed, we agree about a lot of things, it's just that the disagreements stand out more. :-)
 

Posts:27,518
Registered: 11/3/97
Re: compile-time exceptions !!  
Jul 30, 2004 9:48 AM (reply 154 of 202)



 
But the way I approached exceptions evolved before I
ever did that.

What's your position, jschell? Do you think checked
exceptions are a good thing, or an experiment gone
horribly wrong? I'm not looking to pick a fight, just
curious what you think about it.

Wishy-washy.

Like I said I liked the posted links, mainly because I have been feeling guilty about not explicitly passing exact exceptions up the chain but often instead passing Exception (and sometimes even Throwable.)

To a certain extent that comes about because of the following...
- There is no way to handle it anyways. The caller is going to just end up aborting the task in almost all cases.
- Adding the correct code, requires quite a bit of code and makes the real code harder to understand.
- At expected points error handling is added anyways.

I am not going to immediately convert everything to Runtime exceptions, although the posted links will make me consider it in the future.

(I did realize however that it would certainly be nice however if the language actually specified unchecked exceptions as unchecked exceptions rather than just as being anything that isn't checked.)
 

Posts:6,750
Registered: 1/25/04
Re: compile-time exceptions !!  
Jul 30, 2004 9:50 AM (reply 155 of 202)



 
Wishy-washy.

Same here.

(I did realize however that it would certainly be nice
however if the language actually specified unchecked
exceptions as unchecked exceptions rather than just as
being anything that isn't checked.)

How would that look different?
 

Posts:27,518
Registered: 11/3/97
Re: compile-time exceptions !!  
Jul 30, 2004 4:03 PM (reply 156 of 202)



 
Wishy-washy.

Same here.

(I did realize however that it would certainly be
nice
however if the language actually specified unchecked
exceptions as unchecked exceptions rather than just as
being anything that isn't checked.)

How would that look different?

Because right now I can't catch a classification (or even two) for unchecked exceptions and be sure of getting everything. And since Throwable is checked if I rethrow that then I have to declare the method as throwing it. Seems like it would have been better if there had initially just been two explicit trees derived from Throwable.

 

Posts:37,103
Registered: 3/30/99
Re: compile-time exceptions !!  
Jul 30, 2004 4:22 PM (reply 157 of 202)



 
No matter how you structure the code, if you do not
handle a checked exception then the caller will have
to deal with ALL of those checked exceptions even if
you reduce that code block to one line (which then
call various other things to do the processing for 200
lines.)

Yes.

My point was that if the objection to having the entire method body enclosed in a single try block was because many different exceptions would have to be handled in that method, then you could alleviate that by refactoring to smaller methods. You still have the same set of exceptions, but you don't have to handle them in one place.

I realize silk wants the choice to not handle them at all, but since this was specifically addressing a try around a whole method, I was guessing at what one of the complaints about that might be.

Also, there's nothing stopping you from catching those 10 different exceptions with Exception and handing them identically.
 

Posts:37,103
Registered: 3/30/99
Re: compile-time exceptions !!  
Jul 30, 2004 4:25 PM (reply 158 of 202)



 
Because right now I can't catch a classification (or
even two) for unchecked exceptions and be sure of
getting everything.

Huh? What do you mean here?

You can do
catch (RuntimeException exc) {    processUnchecked(exc);}catch (Error exc) {    processUnchecked(exc);}catch (Exception exc) {    processChecked(exc);}
A bit clunky, but if you really want to, it's relatively simple to handle all checked exceptions one way and all unchecked another way.

I do agree that it would be nice to have a more direct way to separate the two though.
 

Posts:2,830
Registered: 9/1/03
Re: compile-time exceptions !!  
Jul 30, 2004 5:07 PM (reply 159 of 202)



 
So there is support for unchecked exceptions.
Silk,
I'll grant you that. I do wonder if your view has
evolved as you've written more C#? Maybe Anders
view
has influenced you there.

Actually, yes, I would suggest that is the case :)

I have done C#.

But the way I approached exceptions evolved before I
ever did that.

Maybe that's because you've been around longer than I have :)

In reality my realisation came after writing many sql-using applications
in c#, and then starting some in java and noticing the difference ...
 

Posts:2,830
Registered: 9/1/03
Re: compile-time exceptions !!  
Jul 30, 2004 5:11 PM (reply 160 of 202)



 
The problem comes when there are many checked
exceptions coming from many
method that you must call, and you just want the
method to work, either because
you are testing, or because you know that it is
okay
for the method to throw an exception.

That's only a problem if it's important that each
method call be tried and caught separately.
Otherwise
you can write a single try and however many catches
you need. If all you're doing is logging (and
possibly rethrowing) one catch block
suffices.

Unfortunately that isn't true.

I would love to use a single catch block like the
following

[snip]

But if I do that then the method must declare
Throwable (and everyone must then catch it) because
Throwable is not an unchecked exception.

well we could always re-throw as some form of RuntimeException (i.e.
bruce eckels class in those links).
 

Posts:21,718
Registered: 98-02-20
Re: compile-time exceptions !!  
Jul 31, 2004 8:27 AM (reply 161 of 202)



 
In reality my realisation came after writing many sql-using applications
in c#, and then starting some in java and noticing the difference ...

Rod Johnson came up with his DataAccessException hierarchy to make exception handling easier for SQL apps.

Silk's wish comes true in Java too, of course. You can always make a design decision to throw only unchecked, runtime exceptions. Now your Java looks just C#.

The difference is that you can also choose to throw a checked exception anytime you want.

As I've said all along, I like having the choice in my hands.

%
 

Posts:2,830
Registered: 9/1/03
Re: compile-time exceptions !!  
Jul 31, 2004 3:38 PM (reply 162 of 202)



 
In reality my realisation came after writing many
sql-using applications
in c#, and then starting some in java and noticing
the difference ...

Rod Johnson came up with his DataAccessException
hierarchy to make exception handling easier for SQL
apps.

Yes, I did something similar .. I created a wrapper around
ResultSet that fixed it :)

Silk's wish comes true in Java too, of course. You
can always make a design decision to throw only
unchecked, runtime exceptions.

Well I do do this, unforunately my code cannot work in an isolated world
without talking to Files or Sockets or Databases, hence the things come
along.
 

Posts:37,103
Registered: 3/30/99
Re: compile-time exceptions !!  
Jul 31, 2004 3:50 PM (reply 163 of 202)



 
Well I do do this, unforunately my code cannot work in
an isolated world
without talking to Files or Sockets or Databases,
hence the things come
along.

Sorry to beat a dead horse, but I really don't see why this is such a problem. Jus wrap your method body in a try block, catch Exception or Throwable, wrap it in a RTE--whether one of Java's or your own--and rethrow. It may not meet your ideal world, but it ends up with essentially the same end result with very little extra work on your part.
 

Posts:2,830
Registered: 9/1/03
Re: compile-time exceptions !!  
Jul 31, 2004 4:30 PM (reply 164 of 202)



 
but I really don't see why
this is such a problem.

You mean Checked Exceptions overall ? You read the links right ? Mine from
bruce-eckels and duffy's one on IBM ? I think they explain it very nicely ... what
problems do you have with those specifically ?

They discuss mainly problems due to misuse. (not my main argument).
They discuss problems due to inappropriate time of handling.
They discuss problems of error-handling code getting into do-something code.
... and other things (i think).

Jus wrap your method body in a
try block, catch Exception or Throwable, wrap it in a
RTE--whether one of Java's or your own--and rethrow.
It may not meet your ideal world, but it ends up with
essentially the same end result with very little extra
work on your part.

Sure, of course there are solutions; it's possible to work-around this problem,
but the work-around isn't as ideal as the fix - i.e. get rid of them ! :) Actually, this
question came about as I was trying to see if it is possible to turn off the consideration
of CheckedExceptions, or perhaps the possibility of some tool which can remove
them from the java compiler's requirements; this is the only way I could see them
being removed.
 
This topic has 202 replies on 14 pages.    « Previous | 1 | ... 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Next »