Your code seems fine to me, maybe try Integer myInt = new Integer(hours),
this throws an exception
or try valueOf instead, here's the API doco.
Class Integer, method: public static Integer valueOf(String s) throws
NumberFormatException
Returns a new Integer object initialized to the value of the specified
String. Throws an exception if the String cannot be parsed as an int. The
radix is assumed to be 10.
Parameters: s - the string to be parsed.
Returns: a newly constructed Integer initialized to the value represented by
the string argument.
Throws: NumberFormatException if the string does not contain a parsable
integer.
-----Original Message-----
From: Routledge, Carl [mailto:[EMAIL PROTECTED]]
Sent: Monday, July 09, 2001 3:12 PM
To: [EMAIL PROTECTED]
Subject: Problem
The code I have attached should throw an exception (using Integer.parseInt)
when a none numerical value is entered and therefore display a message but
it doesn't even though I enter things like too many and uikehfkjsdhiwefd.
Any suggestions on this would be helpful.
public void process (ServletContext sc, HttpServletRequest request,
HttpServletResponse repsone)
throws IOException, ServletException
{
String project = request.getParameter("project");
if (project.equals(""))
{
throw new IOException("Project must must not be empty!");
}
String hours = request.getParameter("hours");
try
{
Integer.parseInt(hours);
}
catch (NumberFormatException e)
{
e.printStackTrace();
throw new IOException("Hours must be an Integer! hours = " + hours);
}
Debug.log (this, "process", "");
}
==========================================================================To
unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST". Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets