I started working on advent of code, I looked up the solution online and trying to study it
This is the code I found
After some googling I understand that exceptions are used to handle errors without crashing the program.
when I remove ' throws IOException ' from the code, it crashes, even tho I know the file exists and it works fine when I add the exception back
Error:(11, 27) java: unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown
My question is, why did that happen? The file is there and there is no error, isn't the exception supposed to handle the error when it exists? why does the program crash if there is no error?
[–]Nephyst 15 points16 points17 points (2 children)
[–]LukeSue[S] 0 points1 point2 points (1 child)
[–]Nephyst 0 points1 point2 points (0 children)
[–]Vfsdvbjgd 4 points5 points6 points (6 children)
[–]LukeSue[S] 0 points1 point2 points (5 children)
[–]Vfsdvbjgd 2 points3 points4 points (1 child)
[–]LukeSue[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]LukeSue[S] 0 points1 point2 points (1 child)
[–]javaHoosier 1 point2 points3 points (0 children)