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 trialboog690
8,987 PointsCode isn't DRY
In the video, Ben Jakuben adds Log.e(TAG, "Exception caught: ", e); to both the IOException catch block and the JSONException catch block.
Well, my question is, how do we make this DRY? I tried:
Log e = Log.e(TAG, "Exception caught: ", e);
outside the try/catch block but e obviously isn't defined at that point. Where do I go from here?
2 Answers
Steve Hunter
57,712 PointsThe only way to make this DRY would be to define a function called, say, catchException
and call that from both places.
There's little point as the line of code doesn't actually bring much to the party; it just logs the error, should one occur, in the system output.
public void catchException(e) {
Log.e("exception caught: ", e)
}
That might work but so would deleting both lines. ;-)
Mohammed Amin
5,445 Pointscatch (IOException | JSONException e) {
Log.e(TAG, "Exception caught: ", e)
}
is something you can try.