Results 1 to 12 of 12
- 03-04-2011, 01:55 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 7
- Rep Power
- 0
unreported exception java.io.IOException
So I'm trying to compile a program that calls the following function:
There's more to this function, but this is where I'm getting the error, I believe.Java Code:public void parseUrl(String source) throws IOException { ... try { .... } } catch (MalformedURLException mue) { System.out.println("MalformedURLException occured"); mue.printStackTrace(); System.exit(1); } catch (IOException ioe) { System.out.println("IOException occured"); ioe.printStackTrace(); System.exit(1); }
This is the compile error:
unreported exception java.io.IOException; must be caught or declared to be thrown
Any ideas? I thought I formatted the try/catch correctly, but I guess not. I'm new to java, so any help would be appreciated.
Thanks!Last edited by fluffaykitties; 03-04-2011 at 03:32 AM.
- 03-04-2011, 02:12 AM #2
The parseUrl method can throw an IOException. Where you call this method you need to handle the exception.
- 03-04-2011, 02:17 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 7
- Rep Power
- 0
Don't I handle it here though with the catch part?
- 03-04-2011, 03:16 AM #4
Member
- Join Date
- Mar 2011
- Posts
- 7
- Rep Power
- 0
Or should I move the catch clauses to where I actually call the function, and throw the exception on that method?
- 03-04-2011, 03:20 AM #5
- 03-04-2011, 03:20 AM #6
- 03-04-2011, 03:31 AM #7
Member
- Join Date
- Mar 2011
- Posts
- 7
- Rep Power
- 0
Oh okay awesome. So all I did was add throws IOException to the method where I call the parseURL exception, and now it works. Thanks!
- 03-04-2011, 03:36 AM #8
Well that is just hiding the problem. Now the method that calls the method that calls parseURL has to handle it. Does it makes sense to do that? Once again the design is upto you.
- 03-04-2011, 03:42 AM #9
Member
- Join Date
- Mar 2011
- Posts
- 7
- Rep Power
- 0
Yes, I think that's okay. Because the method that calls it is actually a constructor with just one line in it's body...the call to parseURL. So if parseURL throws the exception, the constructor just won't be created, and the program will exit.
Correct? (I may be wrong, and if so, please correct me!)
- 03-07-2011, 01:26 AM #10
Member
- Join Date
- Mar 2011
- Posts
- 7
- Rep Power
- 0
anyone? :confused::confused::confused:
- 03-07-2011, 01:50 AM #11
What happened when you tried? Did it compile? Did it run?
- 03-07-2011, 01:59 AM #12
Member
- Join Date
- Mar 2011
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
unreported exception java.lang.Exception; must be caught or declared to be thrown
By arc_remiel in forum New To JavaReplies: 5Last Post: 02-14-2011, 11:39 PM -
unreported IOException problem
By doha786 in forum New To JavaReplies: 5Last Post: 04-20-2010, 11:14 PM -
Unreported exception java.sql.SQLException
By javamula in forum AWT / SwingReplies: 4Last Post: 09-29-2009, 02:32 PM -
unreported exception IOException -- Yet I AM catching it?
By Agathorn in forum New To JavaReplies: 2Last Post: 09-18-2009, 11:22 PM -
Error: unreported exception java.io.IOException; ??
By jonsamwell in forum New To JavaReplies: 5Last Post: 08-24-2008, 04:11 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks