Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Catch SQLServerException

807599May 4 2007 — edited Jun 14 2007
I know that a method can throw an non-runtime exception, so that a calling method can either throw or catch that exception. Right now, I am not so sure of what would happen if I write something that catch a runtime exception.

Here, I am using Eclipse 3.2 and Junit 3.8.1 to catch a particular exception called SQLServerException. The following code is shown as follows:

public void testIncorrectInput() {

try {
Casefile d = Casefile.load("1");
CaseComment.load(d, "w");
} catch (SQLServerException e) {
System.out.println("here");
}
}

The CaseComment.load() method does not explicilty throw SQLServerException but that is where the SQLServerException is coming from. According to the Microsoft Help document, the SQLServerException extends from java.sql.SQLException which also extends from Exception. I assume that I can catch any exception regardless of whether it is a runtime exception or not. The thing is that the Eclipse complained, "Unreachable catch block for SQLServerException. This exception is never thrown from the try
statement body."

Why is this happening? Is my assumption of catching any exception wrong?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 12 2007
Added on May 4 2007
14 comments
4,432 views