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

Ana Cunha
Ana Cunha
8,041 Points

What 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"

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 e) {
  e.printStackTrace();
}
Timothy Williams
Timothy Williams
1,536 Points

should it be

catch (IOException e) {

2 Answers

Peter Do
Peter Do
12,294 Points

I'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
Ana Cunha
8,041 Points

I haven't tried with the IOException, but the challenge asks us to use the generic Exception. It feels like it should work...

Peter Do
Peter Do
12,294 Points

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