Reputation: 21200
I am using a third party library code, calling just one method. The method is declared to throw ZZException, however when running in the real environment, we found this method throwed out IOExceoption sometime.
public void TestMethod() throws ZZException
I am wondering why there is no decalrtion for IOException thrown? If not declaring throw IOException, can IOException being throwed out?
BTW, ZZException is subclass of RuntimeException
Upvotes: 1
Views: 81
Reputation: 37566
Thsi might be an Error in the Library code or and other error in using the library, the best way to know is to report this to the developer including some code and see his answer.
Upvotes: 1
Reputation: 23208
Unless ZZException
is the superclass of IOException
, IOException
can't be thrown out in place of ZZException
. The concept of exception chaining allows you to specify a "cause" for a given exception. Are you sure you are not seeing IOException
in the stack trace as a "cause" for the original ZZException
? It would help if you could show us the stack trace you are getting.
Upvotes: 1
Reputation: 262494
Unless ZZException is a subclass of IOException the method as documented cannot throw an IOException. Most likely the documentation is wrong/outdated. What happens when you compile against the class? Does the compiler think it can throw an IOException?
Another explanation would be that it does not get thrown at all, but it just looks that way in the log file, because the code logs a stacktrace, or because it throws a ZZException that wraps an IOException (as its cause).
Upvotes: 0