... Crap, necrothread
I'll help...
1) Why are checked exceptions stupid?
I've never actually thought about this before, but I see the point. I learned C# first and Java second, and the exception checker in Java always annoys me and causes me to write code just to surpress the compiler errors.
try {
[code that may throw exceptions]
} catch(Exception e) {}
try {
[code that may throw exceptions]
} catch(Exception e) {
throw new RuntimeException(e);
}
I think most of the Java programmers I know do that exact same thing Ken.
It's an old debate, and mine hardly qualifies as expert opinion, but they drive me nuts. Not just the fact that you have to write code to tell the compiler you're aware that a particular method throws a particular exception - that's bad enough - but also that there are other exceptions which aren't checked. Blecch.
try {
[code that may throw exceptions]
} catch(Exception e) {
throw new RuntimeException(e);
}
if (e instanceof IOException)
...
else if (e instanceof NullPointerException)
...
With interviews, you want to start by limiting the chance you hire a total moron. Ask them how to do file I/O, or how exceptions are handled by a try/catch duet... something crazy simple-- maybe how to iterate over a fixed-length array. Ratchet the difficulty up until the programmer can't answer your question... the hire the one that impresses you most.
I've been working as a java developer for the last 4 years and I wouldn't be able to tell you much about file I/O off the top of my head. I work on enterprisey database applications which hardly ever have to work with a file system.
As far as I understand it it's pretty simple. Unchecked Exceptions mean some kind of fatal error (which could be prevented by "correct" programming) from which the application can't recover and must be terminated. Hence there is no need to catch them or declare to throw them because you can't recover anyway like OutOfMemoryError.
A checked exception is an exception from which you can recover and which you have no influence on while programming. Like IOException when out of disk space. The need for having to catch or declaring to throw them is that a user of your API knows what he will have to deal with. A User can't know you are accessing files on hdd.
Code:try { [code that may throw exceptions] } catch(Exception e) { throw new RuntimeException(e); }
I would say this is bad practice too. It's probably manageable if you are the only developer and it's nothing very big/complex. But how do you control that all these runtime exceptions are actually caught? How do you recover from them?
Code:if (e instanceof IOException) ... else if (e instanceof NullPointerException) ...