Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Joshua Wong
Courses Plus Student 572 PointsDon't Understand "This Will Never Happen" line in Try/Catch Block Video
In Craig's video, I don't understand why he has this line:
System.out.println("This will never happen");
in his try statement. He talks about how once the try block breaks b/c the 400 load > MAX_PEZ, it skips that line and goes to the catch. So why have that line at all? He doesn't totally explain why he wrote it and why it's in the try statement.
1 Answer
Kathryn Ann
10,071 PointsHe was illustrating that when the exception occurs, the execution jumps right into the catch block, skipping the rest of the code in the try block, i.e. the print statement was after the line that he knew would cause the exception to be thrown, so it would never be printed. (I think the fact that the rest of the try block is skipped is a common point of confusion when people first learn about try-catch.)
Joshua Wong
Courses Plus Student 572 PointsJoshua Wong
Courses Plus Student 572 PointsThis occurs in the Exceptions Video in "Java Objects" part of the course at around 4:50.