This was an interesting question so I tried it in a command line
program.  The first problem that comes up is when you enter in a
character that's not going parse correctly, such as an alphabetic
character or an equals sign or a space.  Or any combination of one or
more of those characters with valid integers.  In this case, they will
get through the if statement, but cause a NumberFormatException on the
other side in the parseInt() method.  You said the integers are valid,
but I would say some of them must not be.

Scott Stirling

On 16 Jan 2001 08:54:53 -0700, Derek Nerenberg wrote:
> Hello,
> 
> I have some code that roughly resembles this, where the integers are valid integers. 
> For some reason, I keep getting NumberFormatExceptions that I can't reproduce.  
> I've done some printlns when I get the exceptions, and it's showing str1 and/or 
> str2 as null.  But, the guard clause should catch that. To make it more frustrating, 
> these errors wind up killing the connector so my site is down completely.  Restart 
> JRun3.0 and everything is good until next time.  Has anyone run into anything 
>similar 
> or have any ideas?  NT4, IIS4...
>               
> doGet(...)
> {
>       String str1 = req.getParameter( "str1" );
>       String str2 = req.getParameter( "str2" );
> 
>       try
>       {
>               if( str1 == null || str2 == null || "".equals( str1 ) || "".equals( 
>str2 ))
>               {
>                       res.sendRedirect( "/directory/default.htm" );
>                       return;
>               }
>       
>               int num1 = Integer.parseInt( str1 );
>               int num2 = Integer.parseInt( str2 );
>       }
>       catch( IOException ioe )
>       {
>               ...
>       }
>       catch( NumberFormatException nfe )
>       {
>               ...
>       }
> }
> 
> Kindest Regards,
> 
> Derek Nerenberg



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to