471,315 Members | 2,253 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,315 software developers and data experts.

urgent help needed with exception handling.


Hello,
I have the code below :(simplified zip code format)
try
{

Convert.ToInt32(tbOShipPostalCode.Text);
}
catch
{
MessageBox.Show("The zip code must be a number.", "Zip code
error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
The user should only see the messagebox when the input is not a number.

But they see message as if the exception was not beeing handled.
"
A first chance exception of type 'System.FormatException' occurred in
mscorlib.dll

Additional information: Input string was not in a correct format.
"

How can i avoid this message?

Many thanks in advance
JJ
Nov 30 '05 #1
1 1126
Firstly - aren't first chance exceptions specific to the debugger?

Secondly - a better approach is to avoid the exception at all;

int value;
if(int.TryParse(text, out value)) {
// do something useful with value
} else {
MessageBox.Show("Whoops");
}

Marc
"Jack jensen" <Ja*********@mail.dk> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...

Hello,
I have the code below :(simplified zip code format)
try
{

Convert.ToInt32(tbOShipPostalCode.Text);
}
catch
{
MessageBox.Show("The zip code must be a number.", "Zip code error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
The user should only see the messagebox when the input is not a number.

But they see message as if the exception was not beeing handled.
"
A first chance exception of type 'System.FormatException' occurred in
mscorlib.dll

Additional information: Input string was not in a correct format.
"

How can i avoid this message?

Many thanks in advance
JJ

Nov 30 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

24 posts views Thread by Marcin Vorbrodt | last post: by
3 posts views Thread by Master of C++ | last post: by
44 posts views Thread by craig | last post: by
reply views Thread by Kamal Dhingra | last post: by
7 posts views Thread by Gordon Smith | last post: by
8 posts views Thread by Prince Mathew | last post: by
16 posts views Thread by | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.