+ 4
Garbage Collection in java
Why in the above code there is an error "error: unreported exception Throwable; must be caught or declared to be thrown t.finalize(); " If we remove throws Throwable then the required output will be achieved but why? https://code.sololearn.com/c69zyMWBuR13/?ref=app
10 ответов
+ 6
finalize claims to throw a Throwable exception. Therefore, show must catch it or also claim to throw it. If show passes it on, main must also do something about it.
+ 5
I've updated code again. Rerun it.
+ 3
If I add throws to main and show, I only get one t as output same as catching. Try running now.
+ 3
Putting the try catch code puts a filter on exceptions. Each type of exception that has a catch block is processed there and is gone. Those that don't continue being passed up the call chain.
+ 3
All exceptions are subclasses of Throwable so that catch stops them all.
+ 1
I understand how show and main can throw the same exception but can you please rewrite the code on how they can catch it?
0
But in this code the output is only t but if we made show and main to "throws Throwable" then we will get:
t
t
0
How does catch(Throwable error) work?
0
oh,sorry.
But how does the earlier code which has catch(Throwable error) works.
Sorry,I am a beginner.