Welcome to the Treehouse Community
Looking to learn something new?
Thomas Williams9,090 Points
catching an IOException that is thrown automatically
In this lesson where an ObjectOutputStream is used to save an Array using WriteObject a catch block is added to handle an Exception eg ("Problem with saving") but the throw Exception was not written by us in the code, therefore how are we supposed to be aware that we need to catch it? I only know we needed a catch block because craig told me!
Hey there Thomas,
A lot of methods on classes that we use are going to have to be looked up like Craig did, if you remember Craig once didn't catch an exception and his program failed to compile to telling him that there was an uncaught exception.
He did this exactly to get us ready to look at the object just like he did, looking up the ObjectOutputSteam class' java doc We can see that the writeObject method throws multiple methods, and Craig went through and caught and looked at what exceptions it threw, in this objects case the java doc tells us it is possible to get an IOException, so Craig prepared his program to catch it.
Thanks, I hope this helps.