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 trialJoseph Yong
Courses Plus Student 2,920 PointsI 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().
Andy Valdez
2,539 PointsI 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.
Joseph Yong
Courses Plus Student 2,920 PointsThanks to you all for the great help :)
1 Answer
Ben Jakuben
Treehouse TeacherSorry all! Looks like I introduced some sort of bug in that challenge. This should now be fixed.
Ratul Sarna
Courses Plus Student 11,618 PointsRatul Sarna
Courses Plus Student 11,618 PointsIt would helpful if you could paste the code snippet that is causing the error.