473,387 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 1204
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: Marcin Vorbrodt | last post by:
Hi there. How come when in one file i unclude <cmath> i need to use std::tan(...), and in another file i include <cassert> and std::assert fails to compile. Nowhere in my code i do using namespace...
3
by: Master of C++ | last post by:
Hi, I am an absolute newbie to Exception Handling, and I am trying to retrofit exception handling to a LOT of C++ code that I've written earlier. I am just looking for a bare-bones, low-tech...
44
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
0
by: Kamal Dhingra | last post by:
Hi Guys, I am developing an asp.net application .In error handling , I have 2 web.congif files ,one is in Web(which is the virtual directory) ,other i have created in a folder in Web/Admin. The...
7
by: Gordon Smith | last post by:
I have four (4) ASP.NET Web applications/Web sites on a IIS/6 - Windows Server 2003 production server. 3 of them work fine. I just installed the 4th one and it's Application_Start event is not...
8
by: Prince Mathew | last post by:
Hi All, I have a requirement. I am throwing an exception from my user control I want to catch this in my container page. Is this possible? I don't want any event to be raised. PLEASE...
16
by: | last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I keep getting the following error:- Error In:...
5
by: Khamal | last post by:
What is wrong with this public bool syncTOmysqlcon(string Query) { try {string strConnA = "Database=felcradb;Data Source=development;User Id=root;Password=citranet"; MySqlConnection...
1
by: Mike Hofer | last post by:
I really need some help, and I'd appreciate any that you folks can provide. The ASP.NET application in question uses version 1.1 of the .NET Framework. All of the pages use a common base class...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.