8 Feb 07:11
Improvement in handling exception
From: Daniel.Sun <realbluesun@...>
Subject: Improvement in handling exception
Newsgroups: gmane.comp.lang.groovy.jsr
Date: 2007-02-08 06:11:44 GMT
Subject: Improvement in handling exception
Newsgroups: gmane.comp.lang.groovy.jsr
Date: 2007-02-08 06:11:44 GMT
Hi all,
"the Groovy methods will not declare that they throw any checked exceptions
unless you’ve explicitly added the
declaration, even though they might throw checked exceptions at runtime."
quoted from 'Groovy in Action'
I think Groovy should compel programmers to add 'throws XXXException'
explicitly as Java do when defining a method that can throw some exception.
Why do I think it very vital?
For example,
If I define an exception of my own.
class MyException extends Exception {
MyException(String msg) {
super(msg)
}
}
then I instantiate MyException and throw it in myMethod1
def myMethod1() {
throw new MyException("error root")
}
then I invoke myMethod1 in myMethod2
def myMethod2() {
(Continue reading)
Don't forget though the situation:
I am moving from language X to language Y, I do this thing this way in X
why can't I do it this way in Y. Ah you do it that way in Y, but isn't
that ludicrous? If I did it this way in Y learning a lesson from the
way it is done in X then doesn't that work even better in Y? Oh yes.
This is why I like working in multiple languages at all times, the
cross-fertilization of idioms makes for much better programs in all
languages.
RSS Feed