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

Android Android Data Persistence Introduction to Data Persistence Handling an Exception

PD Nghia
PD Nghia
10,536 Points

Challenge: 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

CodeChallenge.java
// 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
STAFF
Ben Jakuben
Treehouse Teacher

Sorry 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.

this bug is still there ben . thanks good work..

George Pirchalaishvili
George Pirchalaishvili
3,747 Points

Most likely that a bug in challenge itself. Everything since good

I 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.....