I saw the following in the downloaded CG correct solution: They put all the Reader/Writer object creations in try blocks. There were several try blocks. But there was not a single catch block anywhere. And the IO-objects were not closed with close() method. How does this thing work? Is it better this way than not using try blocks and closing the streams with the usual close() method? If yes, why?
try block without catch block - ?
You must be signed in to leave a comment
19 September 2021, 12:42
There is no catch block because the method probably throws a Throwable object (i.e. throws Exception).
19 September 2021, 22:19
Thanks, yes it throws.
19 September 2021, 11:46
That's a try-with-resources block. The passed resource has to implement AutoClosable and will be, surprise, automatically closed when leaving the try block. There's no catch block cause CG probably decided to throw the exception up and handle it in the calling method (lots of keywords to google, dumdidum). Yeah, just for you... even if you again ignore me. But I do not care... for you 😜🤪 btw. I'm using this a lot as you can not forget to close resources, eg. here a question of mine
19 September 2021, 22:17
20 September 2021, 05:56
Huhu, Gellert, it is always a pleasure to be able to help you, yeah, yeah 😜🤪