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 trialAna Cunha
8,041 PointsWhat is wrong with my Exception handling?
Seems to me that everything is right, but I'm getting the following error for some reason: "Exception is never thrown in body of corresponding try statement"
// assetManager, assetName, and fileToWrite have been initialized elsewhere
try {
InputStream in = assetManager.open(assetName);
FileOutputStream out = new FileOutputStream(fileToWrite);
copyFile(in, out);
}
catch (Exception e) {
e.printStackTrace();
}
2 Answers
Peter Do
12,294 PointsI'm stuck with the same question... Timothy, I've tried that and had the same result for the code above.
JavaTester.java:22: error: exception Exception is never thrown in body of corresponding try statement } catch(Exception ex) { ^ 1 error
Ana Cunha
8,041 PointsI haven't tried with the IOException, but the challenge asks us to use the generic Exception. It feels like it should work...
Peter Do
12,294 PointsAna - I think we have the code correct too, it compiles correctly... and I saw on another post that someone was having the same issue, and a moderator commented saying he thinks it's an issue with the code challenge and they're working on it.
Timothy Williams
1,536 PointsTimothy Williams
1,536 Pointsshould it be
catch (IOException e) {