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 trialNicolas Hampton
44,638 PointsAutomatic throw in Example.java
I noticed that we didn't have to write a throw into the Example.java to throw the exception. Is that because the Exception errors are already built into these classes that we didn't have to build? Hope I'm phrasing this correctly.
2 Answers
Victor Learned
6,976 PointsYes the compiler will throw run time exceptions automatically. You only manually throw exceptions when you intend to handler them. A good example of this is when working with files. If you intend to read a file typically you'll either check to ensure the file exists then do some action or just try to do the action and then catch the NoSuchFile (not the precise name but you get the point) exception that is thrown.
Michael C
3,230 PointsWe'll actually you don't need to throw an Exception at all. But as you said - there are automatically thrown Exceptions in C#.NET actually, so you might be right - I think it's the same for Java in a common or maybe just a particular case.