J
John B. Matthews
Tom Anderson said:If i ever start a programming blog, i will totally call it Dubious Creeds.
No, Dubious Screeds!
Or a band.
<http://en.wikipedia.org/wiki/Creed_(band)>?
Tom Anderson said:If i ever start a programming blog, i will totally call it Dubious Creeds.
Or a band.
PL/1 uses it pretty much like Java exceptions in that PL/1 exceptionsThat's a bit like exception handling, but more like signal handling,
really. I have no idea how it was scoped; i think it wasn't, and the
last ON ERROR seen was used as the error handler. I understand other
BASICs have ON ERROR too, although i can't comment on how it works.
That ability to ignore errors at will is common to most operating systemShell script has a vaguely exception-like behaviour if you do "set -e":
if any command or function evaluates to a nonzero status, the script
aborts.
It does what's needed. Its always a hard problem to write a commandIt ain't pretty, but, well, let's just say it ain't pretty.
Very cogently argued. ;-}
Pitch said:- exception chaining is nothing more than a reference to the root cause,
thus they have no functional purpose per se, unless we make use of those
references
- using those references brakes [sic] the Law of Demeter
Better alternative is to access only immediate exception, and not to
care about the cause.
Not sure what your point is here. No reference anywhere in programming has a
"functional purpose per se, unless we make use of those references". The
program itself doesn't have a "functional purpose per se, unless we make use
of" it. The definition of "functional" is "we make use of it".
You only use exception chaining when you have a need for wrapped causes.- using those references brakes [sic] the Law of Demeter
That was already refuted upthread.
You are mistaken. The LoD doesn't apply
here because exceptions are "neighbor" classes to the caller; chaining simply
retrieves multiple instances of those neighbor classes.
So you think PassswordException from user's Password-Service and
SqlException [sic] from JDBC are friend classes?![]()
Citation from the Wiki page:
"an object should avoid invoking methods of a member object returned by
another method"
I will set a few examples where this is not so:
For example, take the length property of a string or an array. It is set
internally when the string is created. It is also used for various
calculations internal to String class.
Also, File class. Several properties like length, lastModified,
getParent, isHidden... are set when the object is created.
Also, URL class and itd getUserInfo is set automatically and is used by
several other classes.
Also, class Thread has getPrority, getState that are also used
internally.
Ditto.
You will see that all those properties are set internally and used by
the class or by some other class in the framework. I say they have their
purpose.
But the cause property of an exception is set by the programmer and used
by the programmer so it's a simple helper property. Something like
"Tag" or "Data" in some other languages and framework. It's not
something that will change the behaviour of the class or try-catch block
or enything in the whole JVM.
Pitch said:Arguments are layed out in my previous posts but here they are again:
- exception chaining is nothing more than a reference to the root cause,
thus they have no functional purpose per se, unless we make use of those
references
- using those references brakes the Law of Demeter
Better alternative is to access only immediate exception, and not to
care about the cause.
Lew says...
Pitch said:So you think PassswordException from user's Password-Service and
SqlException [sic] from JDBC are friend classes?![]()
No, I think 'Throwable' is a "friend" type. 'getCause()' doesn't
return 'PasswordException' or 'SQLException'.
Since 'Throwable' is a friend, it's always OK to call methods on a
'Throwable'.
You've missed the point of LoD. Since the caller knows about
'Throwable' and that it has a 'getCause()' method,
Anyway, 'getCause()' is far too useful to let foolish dogma restrict
one's use of it.
That makes it not functional, or somehow implies that we don't make use of it?
But it is something useful for a programmer.
()' method.By your reasoning, we should never use any property that has a 'setX
Data carrying classes are very common.
Far worse alternative.
Better to violate some obscure rule than to not be able to
trouble shoot an application, because the necessary information
is not available.
LoD does not talk about type hierarchy, but of accessing instances.
When you're unrolling/unwrapping chained exceptions you're not violating
that law at all. Each access is to an immediate friend. To think that
this process violates the LoD is like thinking that traversing a linked
list violates that law.
Arved Sandstrom already pointed out:
Pitch, you have completely misconstrued LoD to form a dogma that
interferes with effective programming.
These are my general rules:
- layer X catches everything but RuntimeExceptions and throws
"X_Exception"
- layer Y catches everything but RuntimeExceptions and throws
"Y_Exception"
- GUI/presentation/interface layer catches everything and logs it or
displays a dialog or whatever.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.