473,385 Members | 1,736 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,385 software developers and data experts.

suppress 'variable is declared but never used' for exception variables?

If I have code such as:

catch (WebException WebExcp) {
return false;
}

I will get a warning CS0168: The variable 'WebExcp' is declared but never used

when compiling.

Is there a way to suppress this for individual cases - or failing that,
globally?
--
Thanks in advance, Les Caudle
Nov 16 '05 #1
7 16181
Les,

You can always change the catch to:

catch (WebException)
{
return false;
}

This way, the variable is not declared, and the error doesn't come up.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Les Caudle" <ve**@tiredofspam.com> wrote in message
news:v8********************************@4ax.com...
If I have code such as:

catch (WebException WebExcp) {
return false;
}

I will get a warning CS0168: The variable 'WebExcp' is declared but never used
when compiling.

Is there a way to suppress this for individual cases - or failing that,
globally?
--
Thanks in advance, Les Caudle

Nov 16 '05 #2
Les Caudle wrote:
If I have code such as:

catch (WebException WebExcp) {
return false;
}

I will get a warning CS0168: The variable 'WebExcp' is declared but never used

when compiling.

Is there a way to suppress this for individual cases - or failing that,
globally?


public class Unreferenced {
[System.Diagnostics.Conditional( "DEBUG")]
static public void Parameter( params object [] o)
{
return;
}
}

// ...

try {
//
}
catch (Exception WebExcp) {
Unreferenced.Parameter( WebExcp);
return;
}
--
mikeb
Nov 16 '05 #3
mikeb <ma************@nospam.mailnull.com> wrote:
Is there a way to suppress this for individual cases - or failing that,
globally?


public class Unreferenced {
[System.Diagnostics.Conditional( "DEBUG")]
static public void Parameter( params object [] o)
{
return;
}
}

// ...

try {
//
}
catch (Exception WebExcp) {
Unreferenced.Parameter( WebExcp);
return;
}


While this will work, it would be better just to not declare WebExcp at
all:

catch (Exception)
{
....
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
Jon Skeet [C# MVP] wrote:

While this will work, it would be better just to not declare WebExcp at
all:

catch (Exception)
{
...
}


Normally, yes. However, sometimes I have the exception variable there
so I can examine it when debugging.

--
mikeb
Nov 16 '05 #5
mikeb wrote:
Jon Skeet [C# MVP] wrote:

While this will work, it would be better just to not declare WebExcp
at all:

catch (Exception)
{
...
}


Normally, yes. However, sometimes I have the exception variable there
so I can examine it when debugging.


It also has use for suppressing the warning for unreferenced locals or
method parameters.

I know that in a perfect world the need for this wouldn't exist, but
there are times (particularly for debugging and maintenance of code
whose interfaces can't be modified) that this technique can be useful.

--
mikeb
Nov 16 '05 #6
> public class Unreferenced {
[System.Diagnostics.Conditional( "DEBUG")]
static public void Parameter( params object [] o)
{
return;
}
}

// ...

try {
//
}
catch (Exception WebExcp) {
Unreferenced.Parameter( WebExcp);
return;
}


sorry, WHAT?
you catch the exception into an object, pass it thru a class where you dont
handle it ??? - did i miss the superpoint on this, or is this just useless?
Nov 16 '05 #7
Am Sat, 19 Jun 2004 05:25:19 +0200 schrieb Crea-Ue. Kirdar:
sorry, WHAT?
you catch the exception into an object, pass it thru a class where you dont
handle it ??? - did i miss the superpoint on this, or is this just useless?


forget it, i saw the answer to jons post too late, sorry. :)
Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Oplec | last post by:
Hi, I thought that I understood how C++ allows for the declaration and defining of variables within an if() statement and how the declared variable can be used until the end of the major if()...
8
by: harry | last post by:
Hi, During compilation, a C# project in my solution triggers the following warning: "warning CS0168: The variable 'ex' is declared but never used" To trigger this warning, it appears the C#...
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
20
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
7
by: What-A-Tool | last post by:
In the following code, "catch" is underlined in blue, and the error "the variable fx is declared but never used" is displayed when I mouse hover over it. Am I doing something wrong, or do I just...
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
0
MMcCarthy
by: MMcCarthy | last post by:
We often get questions on this site that refer to the scope of variables and where and how they are declared. This tutorial is intended to cover the basics of variable scope in VBA for MS Access. For...
11
by: =?UTF-8?Q?Filip_Gruszczy=C5=84ski?= | last post by:
Hello everyone! It is my first message on this list, therefore I would like to say hello to everyone. I am fourth year student of CS on the Univeristy of Warsaw and recently I have become very...
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: 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: 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...
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.