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

Java Java Data Structures Efficiency! Design the UI

How do you decide where is a good place to catch an exception?

When Craig used the "readLine()" method he said that he didn't want to catch it in the same method but bubble up the exception instead, it wasn't clear to me why it was done this way.

1 Answer

Sławomir Lasik
Sławomir Lasik
7,792 Points

Well think about it.

Let's assume that he catches it when he uses readLine() method. This is a private method. So the programmer who is using this class doesn't even know about this method. And how it works. And that it handles exceptions. But he is aware that it might go something wrong in giving input. He is not able to handle it how he wants to. Because it is done already in this private method. And what if the situation when the exception is thrown is not handled how the programmer using this class want to handle.

Its a really design issue I think. Its up to the user of the class (or method) how he handles the exceptions in this situation.