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

I have called printStackTrace() in my catch block (ge.printStackTrace()), but the compiler keep asking me to call it.

I have even added an IOException to catch the exception thrown by copyFile but it keeps asking me to printStackTrace().

Ratul Sarna
Ratul Sarna
Courses Plus Student 11,618 Points

It would helpful if you could paste the code snippet that is causing the error.

Andy Valdez
Andy Valdez
2,539 Points

I haven't done any of the videos, but I am a Java developer. As far as I can tell something is not right from their end. This is my code:

try {
  InputStream in = assetManager.open(assetName);
  FileOutputStream out = new FileOutputStream(fileToWrite);
  copyFile(in, out);
}
catch(Exception exception) {
  exception.printStackTrace();
}

Yet it also keeps asking me to call it. In fact, if I try to catch IOException and then Exception I get no error. So Joseph, I don't think what you are doing is wrong.

Oh, and after I thought about it some more and looked at the error:

JavaTester.java:45: error: unreported exception IOException; must be caught or declared to be thrown
  copyFile(in, out);
          ^
1 error

I think the issue is in the method copyFile(). It needs to throw an IOException. It doesn't, so we can't catch it. The error is in code we can't access.

Thanks to you all for the great help :)

1 Answer

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Sorry all! Looks like I introduced some sort of bug in that challenge. This should now be fixed.