Talk:Exceptions/Catch an exception thrown in a nested call: Difference between revisions

Content added Content deleted
(What if you don't say what something throws in Java?)
Line 14: Line 14:
==A question on Java==
==A question on Java==
If you changed <code>public static void foo() throws U1</code> to remove the reference to it throwing U1, would that always be a compile time error? --[[User:Paddy3118|Paddy3118]] 05:14, 1 May 2009 (UTC)
If you changed <code>public static void foo() throws U1</code> to remove the reference to it throwing U1, would that always be a compile time error? --[[User:Paddy3118|Paddy3118]] 05:14, 1 May 2009 (UTC)
:Yes. You could change it to <code>throws Exception</code>, but then you would have to surround all calls to the function with a <code>try</code> block which would <code>catch(Exception e)</code>, which would then catch the U1 Exception and fail to meet the task requirements. I'm not sure if Java could do this task (or if it would even be good practice in any language). --[[User:Mwn3d|Mwn3d]] 05:47, 1 May 2009 (UTC)