> I have an ID which I pass from the QueryString["id"]. The id is integer only
> and I want before performing any action to validate if the Id is valid
> integet.
Alexey,
You should do some research on using Try/Catch to take care of programming
logic. Doing so should be avoided at all cost. Using Try/Catch is very
inneficient and can make applications perform very slowy.
Aidy's example utilizing TryParse is an incredibly more efficient way to
handle this.
Regards,

Signature
S. Justin Gengo, MCP
justin@aboutfortunate[-NoSpam-].com
Free code library at:
www.aboutfortunate.com
>> I have an ID which I pass from the QueryString["id"]. The id is integer
>> only
[quoted text clipped - 9 lines]
> return; // id is wrong
> }
Göran Andersson - 23 Jul 2007 22:19 GMT
> Alexey,
>
[quoted text clipped - 4 lines]
> Aidy's example utilizing TryParse is an incredibly more efficient way to
> handle this.
In this case either way is valid. A non-integer value might very well be
considered to be an exceptional situation. In that case performance is
not an issue. It's true that exceptions should not be used in normal
program flow, but if the validation fails, the normal program flow is
out of the picture anyway.
-
The catch, however, should _not_ catch any exception, it should catch
only FormatException and OverflowException. Don't catch exceptions that
you don't know how to handle.
Also the code handling the exception should _not_ simply do a return, it
should actually handle the situation.

Signature
Göran Andersson
_____
http://www.guffa.com