473,378 Members | 1,133 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,378 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 1202
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.