codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  problem with Exception  gosi at 14:04 on Thursday, June 29, 2006
 

Hi,

I don't understand why I get a error here, any help really appreciatet :)

this is the error I get from the last catch block:

Unreachable catch block for IOException. This exception is never thrown from the try statement body



import java.io.*;
import java.net.*;


public class OutputThread extends Thread
{
PrintWriter write;
protected static Socket out;
protected static DataOutputStream output;
protected String choice = "";
protected String newProduct = "";
protected String newPrice = "";
protected String newAmount = "";

public OutputThread (Socket clientSocket)
{
out = clientSocket;
write = null;

}

public void setChoice(String choice)
{
this.choice = choice;
}

public void addProduct(String newProduct, String newPrice)
{
this.newProduct= newProduct;
this.newPrice = newPrice;
}
public void addSale (String newProduct, String newAmount)
{
this.newProduct = newProduct;
this.newAmount = newAmount;
}

protected static void initialize()
{
try
{
output = new DataOutputStream(out.getOutputStream());

}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}

public void sendData(double data)
{
try
{
output.writeDouble(data);

}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
public void run()
{
try
{
write = new PrintWriter(out.getOutputStream(), true);

}
catch (UnknownHostException e)
{
System.out.println(e.getMessage());
System.exit(1);
}
catch (IOException e)
{
System.err.println(e.getMessage());
System.exit(1);
}


try
{

BufferedReader stdIn = new BufferedReader(
new InputStreamReader(System.in));
String userInput;


while (!choice.equals(null))
{

if(choice.equals("1"))
{
write.println("addProduct");
userInput = newProduct;
write.println(userInput);
userInput = newPrice;
write.println(userInput);
choice = "0";
}
else if(choice.equals("2"))
{
write.println("addSales");
userInput = newProduct;
write.println(userInput);
userInput = newAmount;
write.println(userInput);
choice = "0";
}
else if(choice.equals("3"))
{
write.println("getTotalValue");
choice = "0";
}

}

}

catch(IOException e)
{
System.out.println(e.getMessage());
}
}

}


  Re: problem with Exception  crwood at 23:14 on Thursday, June 29, 2006
 

The class compiles okay without it.

// try
// {
BufferedReader stdIn = new BufferedReader(
new InputStreamReader(System.in));
String userInput;

while (!choice.equals(null))
{
if(choice.equals("1"))
{
write.println("addProduct");
userInput = newProduct;
write.println(userInput);
userInput = newPrice;
write.println(userInput);
choice = "0";
}
else if(choice.equals("2"))
{
write.println("addSales");
userInput = newProduct;
write.println(userInput);
userInput = newAmount;
write.println(userInput);
choice = "0";
}
else if(choice.equals("3"))
{
write.println("getTotalValue");
choice = "0";
}
}
// }
// catch(IOException e)
// {
// System.out.println(e.getMessage());
// }
}









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: Function to check the pattern(i.e 1A-2B-3C)
•  Re: problem with Exception
•  Re: Turning java class into application
•  Re: this is weird
•  Server Name or Address could not be resolved?
•  Re: How can I read ASCII data file in C++
•  Sending automated emails
•  Re: How to kill framesets
•  What is This?


Recent Articles
What is a pointer in C?
Multiple submit buttons with form validation
Understanding Hibernate ORM for Java/J2EE
HTTP screen-scraping and caching
a javascript calculator
A simple way to JTable
Java Native Interface (JNI)
Parsing Dynamic Layouts
MagicGrid
Caching With ASP.Net


© Copyright codetoad.com 2001-2006