Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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) {

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
Ben Jakuben
Treehouse Teacher

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