Groups | Blog | Home
all groups > c# > february 2005 >

c# : Avoiding the warning of not using Exception variable in catch


Michael H
2/26/2005 9:54:51 PM
On Sat, 26 Feb 2005 22:33:35 -0700, "Jack Addington"
[quoted text, click to view]

the command line paramater would be /w:0

like:

C:> csc.exe myApp.cs /w:0




Michael Hughes - Silverton, Oregon
http://wou.ath.cx/Trivia
Jack Addington
2/26/2005 10:33:35 PM
I have a 3rd control that throws an exception if the syntax of a method call
is incorrect. I am passing dynamic strings to that method so it is
acceptable that the method will fail. I have my try...catch setup as

try{ ...}
catch(Control.StrangeException sEx){ }

I get a compiler warning that I am not using sEx. I don't want to do
anything if the method fails and I would like the warnings to go away... any
ideas?

thx

jack

Jon Skeet [C# MVP]
2/27/2005 7:30:26 AM
[quoted text, click to view]

Just don't include the variable:

catch (Control.StrangeException) { }

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
sadhu
2/27/2005 10:41:38 AM
It would have been nice if the compiler allowed the same thing for
unused method parameters also. Like
int SomeFunc(int x, int);

Regards
Senthil
Jon Skeet [C# MVP]
2/27/2005 8:34:36 PM
[quoted text, click to view]

I think that's a much rarer situation, myself - and one which should
have very clear documentation to say that you *will* be ignoring the
parameter's value.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
Jack Addington
2/28/2005 9:46:27 AM
Couldn't be easier... thx

jack

[quoted text, click to view]

AddThis Social Bookmark Button