Skip to main content
GameDev.net gamedev.net
🔒 Locked

Exception question (Java)

Started by Dark One Mar 10, 2003 at 6:59 PM 0 replies 250+ views
Original Post
Dark One
Dark One
Let''s say I have three function, A, B and C. Function A calls function B which calls function C. Now C throws exception E which is handled by A but not by B. My question is, will the exception "travel down" to A so that it can handle it or not? Hope it made any sense. Thanks in advance.
Advanced Bug
Advanced Bug
There are two different situations:

1) If the exception E is runtime exception (for example NullPointerException, NegativeArraySizeException, see more in documentation for java.lang.RuntimeException) then it will "travel down" to A.

2) If E is not a runtime exception, Java compiler will require you either to catch it in function B, or declare that function B throws E, and then you''ll have to catch it in A (or declare that A throws E, too).

In either case, you can write your functions in such way that E is caught in A.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.