-
Exception Handlers in java............
Iam trying to write the input from text file into an automotive object.
public void readFile(Automotive a1)
{
BufferedReader inputstream=null;
BufferedWriter outputstream=null;
StringTokenizer st;
try
{
inputstream = new BufferedReader(new FileReader("C:\\CarInputData.txt"));
outputstream = new BufferedWriter(new FileWriter("C:\\CarOutputData.txt"));
String line= inputstream.readLine();
st = new StringTokenizer(line,":");
a1.setName(st.nextToken());
outputstream.write("Car Model :" + a1.getName());
outputstream.newLine();
outputstream.newLine();
catch(NullPointerException e)
{
System.out.println("Null Pointer Exception ");
}
catch(NumberFormatException nfe)
{
System.out.println("Cannot read the number ");
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("Array out of Bounds Exception");
}
catch (FileNotFoundException e)
{
System.out.println("File not found!");
try
{
inputstream.close();
outputstream.close();
}
catch (IOException ioe) {} // disregard close failure
}
catch (IOException e)
{
e.printStackTrace();
try
{
inputstream.close();
outputstream.close();
}
catch (IOException ioe) {} // disregard close failure
System.out.println("Unable to read file!");
}
}// end of readFile
-------------------------------------------------------------------
I have the following requirements:
1.Create an exception handler so it handles at least 5 exceptions
2.(Optional) Enhance your design and code to create any abstract classes so the code is extensible and reusable.
Nothing more is mentioned about them.....
Is my analysis to create a custom exception right???
-
reply
here's a code that i've made:
// CAutomotive.java
// 2007-May-10
package automotive;
import java.awt.*;
import javax.swing.*;
import java.io.*;
public final class CAutomotive {
// attribute(s)
private JFrame jframe;
private JComboBox jcboList;
// constructor(s)
public CAutomotive(String title) {
jframe.setDefaultLookAndFeelDecorated( true );
jframe = new JFrame( title );
jcboList = new JComboBox();
} // close CAutomotive(String)
// accessor(s)
public void setProperties() {
jcboList.setBackground( Color.WHITE );
try {
BufferedReader input =
new BufferedReader( new FileReader("C:\\automotive\\cls\\car_input_data.txt") );
String s = "";
while( (s = input.readLine() ) != null ) {
jcboList.addItem( s );
} // close while
} catch (IOException e) {
} // close try catch
} // close setProperties()
// other method(s)
public void launchFrame() {
setProperties();
jframe.getContentPane().add( jcboList, BorderLayout.NORTH );
jframe.setSize( 200, 200 );
jframe.setResizable( false );
jframe.setVisible( true );
} // close launchFrame()
} // close CAutomotive class
why do you need to have a lot of exceptions?....
what is the purpose of your Automotive object?...
can you explain more so I can help you?...
Similar Threads
-
Replies: 9
Last Post: 09-19-2007, 05:58 AM
-
Replies: 1
Last Post: 05-13-2005, 06:46 AM
-
By David Williams in forum .NET
Replies: 1
Last Post: 05-28-2002, 02:19 PM
-
By JJ in forum Enterprise
Replies: 1
Last Post: 07-06-2000, 04:50 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks