Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 1st, 2008, 04:58 PM
Authorized User
 
Join Date: Aug 2008
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default Warning Message (Exception ex)

I am receiving the following warning message when I do a build:


C:\BegASPNET\Site\Controls\ContactForm.ascx.cs(77, 26): warning CS0168: The variable 'ex' is declared but never used

Here is the code:

 try
        {
            mySmtpClient.Send(myMessage);
        }
        catch (Exception ex)
        {
            lblMessage.Text = "An error occurred while sending your e-mail. Please try again.";
        }

Why might I be getting this error?

 
Old December 1st, 2008, 05:18 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

The warning is telling you that you declare a variable (ex) that you never use.

The ex variable is declared in the catch block but then you never use it. Either get rid of it altogether, or use it for something useful. That is, change the code to this:
Code:
catch (Exception)
{
  lblMessage.Text = "An error occurred while sending your e-mail. Please try again.";
}
or this
Code:
catch (Exception ex)
{
  lblMessage.Text = "An error occurred while sending your e-mail. Please try again. Details: " + ex.Message;
}
The latter is not a good solution as it provides detailed error information to the client. However, it's good to now you can access the ex variable so you can log it to an error log like a database for example.

For more info and detailed explanations:

http://www.google.com/search?hl=en&q...+never+used%22

Cheers,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Warning Window Message in Struts!!! petemotu Struts 0 September 25th, 2006 08:48 PM
Warning C4530: C++ exception handler used, but unw bluebeta Visual C++ 2 April 27th, 2006 09:00 PM
Warning message NutzyNobs Beginning PHP 1 July 28th, 2005 02:31 PM
Back button create warning message Mantis HTML Code Clinic 0 May 19th, 2005 07:00 AM
Warning Message AMP_Engineer BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 4 September 29th, 2004 08:55 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.