[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[OT] Java is fun! (was Re: [Gnu-arch-users] Nit)
From: |
Tom Lord |
Subject: |
[OT] Java is fun! (was Re: [Gnu-arch-users] Nit) |
Date: |
Wed, 22 Oct 2003 11:21:07 -0700 (PDT) |
from
http://java.sun.com/docs/books/jls/second_edition/html/binaryComp.doc.html#44952
13.4.19 Method and Constructor Throws
Changes to the throws clause of methods or constructors do not
break compatibility with existing binaries; these clauses are
checked only at compile time.
from
http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#79311
14.20 Unreachable Statements
It is a compile-time error if a statement cannot be executed
because it is unreachable. Every Java compiler must carry out
the conservative flow analysis specified here to make sure all
statements are reachable.
[....]
* A catch block C is reachable iff both of the following are true:
Some expression or throw statement in the try block is
reachable and can throw an exception whose type is
assignable to the parameter of the catch clause C. (An
expression is considered reachable iff the innermost
statement containing it is reachable.) There is no
earlier catch block A in the try statement such that the
type of C's parameter is the same as or a subclass of the
type of A's parameter.
from
http://java.sun.com/docs/books/vmspec/2nd-edition/html/VMSpecTOC.doc.html
[silence]
It apparently takes a heck of a lot of `catch (Throwable e)'
clauses to write a general purpose Java package that actually
honors its `throws' contracts.
Earlier we saw an example of Java that went:
public List getLinesOfFile(String f) throws IOException {
String realFile=translatePath(f);
InputStream is=openTheStream(realFile);
List rv=getLinesOfStream(is);
is.close();
return(rv);
}
where it was presumed that all of the called methods have `throws
IOException' or no `throws' decl at all. Shouldn't that code really
be (usual Java syntax disclaimer):
public List getLinesOfFile(String f) throws IOException {
try {
String realFile=translatePath(f);
InputStream is=openTheStream(realFile);
List rv=getLinesOfStream(is);
is.close();
return(rv);
} catch (IOException e) {
throw e;
} catch (Throwable e) {
// catch fire
//
}
}
otherwise, what about the unfortunate caller who has code:
try {
List lines=Reader.getLinesOfFile(fileName);
Answer a=Parser.parseLines(lines);
} catch (IOException e) {
...
} catch (ParserException e) {
...
}
Hey, who _really_ raised that ParserException?
-t
- Re: [Gnu-arch-users] Nit, (continued)
- Re: [Gnu-arch-users] Nit, Robin Farine, 2003/10/21
- Re: [Gnu-arch-users] Nit, Tom Lord, 2003/10/21
- Re: [Gnu-arch-users] Nit, Dustin Sallings, 2003/10/21
- [Gnu-arch-users] Re: Nit, Miles Bader, 2003/10/21
- [Gnu-arch-users] Re: Nit, Miles Bader, 2003/10/22
- [Gnu-arch-users] Re: Nit, Dustin Sallings, 2003/10/22
- [Gnu-arch-users] Re: Nit, Tom Lord, 2003/10/22
- Re: [Gnu-arch-users] Nit, Tom Lord, 2003/10/22
- Re: [Gnu-arch-users] Nit, Robert Collins, 2003/10/22
- Re: [Gnu-arch-users] Nit, Tom Lord, 2003/10/22
- [OT] Java is fun! (was Re: [Gnu-arch-users] Nit),
Tom Lord <=
- [Gnu-arch-users] Re: [OT] Java is fun!, zander, 2003/10/22
- Re: [Gnu-arch-users] Re: [OT] Java is fun!, Dustin Sallings, 2003/10/22
- Re: [Gnu-arch-users] Re: [OT] Java is fun!, Tom Lord, 2003/10/22
- Re: [Gnu-arch-users] Re: [OT] Java is fun!, Dustin Sallings, 2003/10/22
- Re: [Gnu-arch-users] Re: [OT] Java is fun!, Miles Bader, 2003/10/22
- Re: [Gnu-arch-users] Re: [OT] Java is fun!, Tom Lord, 2003/10/22
- Re: [Gnu-arch-users] Re: [OT] Java is fun!, Tom Lord, 2003/10/22
- [Gnu-arch-users] Re: [OT] Java is fun!, zander, 2003/10/22
- Re: [Gnu-arch-users] Re: [OT] Java is fun!, Tom Lord, 2003/10/22
- Re: [Gnu-arch-users] Re: [OT] Java is fun!, Thomas Zander, 2003/10/23