Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
Eclipse Collections Categorically: Level up your programming game
this week in the
Open Source Projects
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Ron McLeod
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Beginning Java
exception java.io.IOException is never thrown in body of corresponding try statement
Bud Tippins
Ranch Hand
Posts: 52
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I'm getting an error "exception java.io.IOException is never thrown in body of corresponding try statement" on line #16.
What is wrong with my code? Any insights appreciated. Thank you.
package practice2; import java.io.*; public class Practice2 { public static void main(String[] args) { Practice2 p2 = new Practice2(); p2.go(); } void go() { try { File myDir = new File("myDir"); myDir.mkdir(); } catch(IOException e){ } } }
Matthew Brown
Bartender
Posts: 4568
9
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Have a look at the Javadocs for the
File
class. What exceptions can the constructor and
mkdir
throw?
Joanne Neal
Rancher
Posts: 3742
16
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
It's saying that catching an IOException is unnecessary because none of the code in the try block ever throws an IOException. In other words you don't need to surround lines 14 and 15 in a try/catch.
Joanne
Bud Tippins
Ranch Hand
Posts: 52
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks guys. Based on your comments I got it fixed.
Pavitra Chaudhary
Greenhorn
Posts: 1
posted 2 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
If you wanted to use try catch then use Exception instead of IOException.
Campbell Ritchie
Marshal
Posts: 80965
526
posted 2 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Welcome to the Ranch h:)
I wouldn't try to catch any exceptions there. I don't like
catch (Exception ex) ...
because it is too non‑specific.
And when my army is complete, I will rule the world! But, for now, I'm going to be happy with this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
One more on exceptions
Exception Handling
Exception
PrintWrite close() does not catches Exception
IOMessage
More...