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 trialPD Nghia
10,536 PointsChallenge: Handling An Exception
The code below has the potential to throw an exception. Wrap this code in a try/catch so it can gracefully react to an exception. Catch the generic Exception to cover all types of exceptions. In the catch block, call printStackTrace() using the exception parameter.
I worked but notification error ??? try{ InputStream in = assetManager.open(assetName); FileOutputStream out = new FileOutputStream(fileToWrite); copyFile(in, out); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
ERROR:
JavaTester.java:22: error: exception Exception is never thrown in body of corresponding try statement } catch(Exception ex) { ^ JavaTester.java:60: error: exception IOException is never thrown in body of corresponding try statement } catch (IOException e) { ^ JavaTester.java:55: error: unreported exception IOException; must be caught or declared to be thrown InputStream in = assetManager.open(assetName); ^ JavaTester.java:57: error: unreported exception Exception; must be caught or declared to be thrown copyFile(in, out); ^ 4 errors
// assetManager, assetName, and fileToWrite have been initialized elsewhere
try{
InputStream in = assetManager.open(assetName);
FileOutputStream out = new FileOutputStream(fileToWrite);
copyFile(in, out);
}catch(Exception ex){
ex.printStackTrace();
}
3 Answers
Ben Jakuben
Treehouse TeacherSorry for the trouble here! There was a bug in how our code challenge engine was capturing Exceptions. We just fixed it and this should now pass.
George Pirchalaishvili
3,747 PointsMost likely that a bug in challenge itself. Everything since good
Joseph Ambrose
6,629 PointsI had the same problem. I even got annoyed and added IOException and FileNotFoundException to see if I could get it to do anything. I even tried adding a finally to the try/catch and still nothing.
TREEHOUSE you have a bug.....
vibhor gupta
Courses Plus Student 1,053 Pointsvibhor gupta
Courses Plus Student 1,053 Pointsthis bug is still there ben . thanks good work..