Avoiding the warning of not using Exception variable in catch

  • Thread starter Thread starter Jack Addington
  • Start date Start date
J

Jack Addington

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
 
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

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
http://wou.ath.cx/AmateurRadio
 
Jack Addington said:
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?

Just don't include the variable:

catch (Control.StrangeException) { }
 
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
 
sadhu said:
It would have been nice if the compiler allowed the same thing for
unused method parameters also. Like
int SomeFunc(int x, int);

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.
 
Back
Top