Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 16th, 2003, 01:55 AM
EHendriks EHendriks is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2002
Location: Amersfoort, The Netherlands
Posts: 10 EHendriks User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 37 sec
Reputation Power: 0
IOException not catched

I have written a method that read a file and interprets the keywords and values in it. It works fine, but if I change the call in the JSP-page and offer the method a filename that doesn't exist, the IOException isn't catched.
In stead, Apache Tomcat gives the error: Apache Tomcat/4.0.1 - HTTP Status 404 - c:\jdtbc2.txt (The system cannot find the file specified)

The header of the method in the bean:
public void read_ini_file(String filename) throws IOException {
.
.
.
try {
FileInputStream fis =new FileInputStream(inputfile);
InputStreamReader isr =new InputStreamReader(fis);
BufferedReader r =new BufferedReader(isr);
line=r.readLine();
//2003-01-08 EHE: (linenumber=in.read())!=-1
while(line!=null) {
if(line.length()>0) {
.
.
}
Catch(FileNotFoundException fnfe) {
.
.
}
Catch(IOException ioe) {
.
.
}
Catch(NullPointerException npe) {
.
.
}
Catch (Exception e) {
.
.
}

None of the exceptions are ctached when offering the mehod a unknown filename....

Suggestions?

Reply With Quote
  #2  
Old January 18th, 2003, 02:41 PM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 35 m 19 sec
Reputation Power: 111
I am not real clear on what you are saying, so I will throw a few things out here.

The first odd thing I notice is that you specify that your method throws and IOException, yet you are attempting to catch that same IOException in the method. If nothing else this is confusing as to your intentions. Do you wish the caller of the method read_ini_file to catch the IOException or do you want to catch it in the read_ini_file method itself?

As your code is now, the FileNotFoundException should be caught in the first catch block after your try block (You are getting a FileNotFoundException in this case, which does indeed extend IOException). What are you doing in that catch block since your code fragment is incomplete?

Reply With Quote
  #3  
Old January 20th, 2003, 02:43 AM
EHendriks EHendriks is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2002
Location: Amersfoort, The Netherlands
Posts: 10 EHendriks User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 37 sec
Reputation Power: 0
First of all, thanks for your reply.

The intention is to catch all exceptions in the method. In the catch section, errorcodes and errormessages are set, which can be read out by getProperties.


If you have any other suggestions, please let me know.


Erwin

Reply With Quote
  #4  
Old January 23rd, 2003, 12:28 AM
DC Dalton DC Dalton is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: NE Pa.
Posts: 96 DC Dalton User rank is Private First Class (20 - 50 Reputation Level)DC Dalton User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 h 29 m 32 sec
Reputation Power: 8
You shoul always wrap you reads in a conditional statement to avoid this. I also agree with the previous comment about catching & throwing...its one or the other & usually a good idea to catch the exceptions so you can handle them specifically, not mix them into a bunch of exceptions that you can sort out.

Here's an example of some code where I read the content for the web page into a servlet...note the conditions:

java.net.URL url = getServletContext().getResource("/sitePages/"+pageName+".txt");
java.io.InputStream is = url.openStream();

if (is != null) {
java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader(is));
String s;
while ((s = br.readLine()) != null) {
sb.append(s);
sb.append("\n");
}
br.close();
is.close();
}
__________________
DC Dalton
DCD Designs
SCJP

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > IOException not catched


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT