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

avoid compiler warnings

Imagine you have the following code:

try
{
...
}
catch (ThreadAbortException eThread)
{
if (WorkStopped != null) WorkStopped(this, EventArgs.Empty)
}

How can I avoid the 'The variable 'eThreadAbort' is declared but never
used.'?
I think this warning is useful in most contexts, but in catch blocks many
many times the caugth object is not used, you only want to know what type of
error occurred. And I don't want the compiler to avoid this warning always,
only in catch blocks.

I could cheat it, doing:

try
{
...
}
catch (ThreadAbortException eThread)
{
#if DEBUG
UseExceptionObject(eThread);
#endif
if (WorkStopped != null) WorkStopped(this, EventArgs.Empty);
}

#if DEBUG
private void UseExceptionObject(Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
}
#endif

But it would be great an option in the compiler to solve this, or maybe the
compiler already has this option?
Another way could be adding an attribute NotUsedAttiribute and assigning it
to the parameter declaration.
Also I could leave the warnings, but with a big program having 'false
warnings' mixed with real warnings and errors is a mess.

Thank you.
Nov 15 '05 #1
2 1692
Just leave off the variable that names the exception (eThread), as in:

try
{
...
}
catch (ThreadAbortException)
{
if (WorkStopped != null) WorkStopped(this, EventArgs.Empty)
}

"Samuel" <no*****@noserver.com> wrote in message
news:OS**************@TK2MSFTNGP11.phx.gbl...
Imagine you have the following code:

try
{
...
}
catch (ThreadAbortException eThread)
{
if (WorkStopped != null) WorkStopped(this, EventArgs.Empty)
}

How can I avoid the 'The variable 'eThreadAbort' is declared but never
used.'?
I think this warning is useful in most contexts, but in catch blocks many
many times the caugth object is not used, you only want to know what type of error occurred. And I don't want the compiler to avoid this warning always, only in catch blocks.

I could cheat it, doing:

try
{
...
}
catch (ThreadAbortException eThread)
{
#if DEBUG
UseExceptionObject(eThread);
#endif
if (WorkStopped != null) WorkStopped(this, EventArgs.Empty);
}

#if DEBUG
private void UseExceptionObject(Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
}
#endif

But it would be great an option in the compiler to solve this, or maybe the compiler already has this option?
Another way could be adding an attribute NotUsedAttiribute and assigning it to the parameter declaration.
Also I could leave the warnings, but with a big program having 'false
warnings' mixed with real warnings and errors is a mess.

Thank you.

Nov 15 '05 #2
Thank you very much Fred.

"Fred Mellender" <no****************@frontiernet.net> wrote in message
news:am******************@news02.roc.ny...
Just leave off the variable that names the exception (eThread), as in:

try
{
...
}
catch (ThreadAbortException)
{
if (WorkStopped != null) WorkStopped(this, EventArgs.Empty)
}

"Samuel" <no*****@noserver.com> wrote in message
news:OS**************@TK2MSFTNGP11.phx.gbl...
Imagine you have the following code:

try
{
...
}
catch (ThreadAbortException eThread)
{
if (WorkStopped != null) WorkStopped(this, EventArgs.Empty)
}

How can I avoid the 'The variable 'eThreadAbort' is declared but never
used.'?
I think this warning is useful in most contexts, but in catch blocks many many times the caugth object is not used, you only want to know what
type of
error occurred. And I don't want the compiler to avoid this warning

always,
only in catch blocks.

I could cheat it, doing:

try
{
...
}
catch (ThreadAbortException eThread)
{
#if DEBUG
UseExceptionObject(eThread);
#endif
if (WorkStopped != null) WorkStopped(this, EventArgs.Empty);
}

#if DEBUG
private void UseExceptionObject(Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
}
#endif

But it would be great an option in the compiler to solve this, or maybe

the
compiler already has this option?
Another way could be adding an attribute NotUsedAttiribute and assigning

it
to the parameter declaration.
Also I could leave the warnings, but with a big program having 'false
warnings' mixed with real warnings and errors is a mess.

Thank you.


Nov 15 '05 #3

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

Similar topics

5
by: dis | last post by:
I've been going through my code and clearing away some of the compiler warnings that i'm generating and i've come across areas where i cast pointers to integer values. The Visual Studio compiler...
20
by: News | last post by:
I'm new to c and gcc. I was wondering if anyone can point me to a web page or book that has a list of the warning messages and their meanings. Are the warnings the same no matter what compiler...
2
by: Sensorflo | last post by:
Im writting my own logger. Below is a very simplified snip of code, which illustrates my question. A message is Logged with the macro Log( priority, msg ). The message is only actually logged, if...
43
by: Anitha | last post by:
Hi I observed something while coding the other day: if I declare a character array as char s, and try to use it as any other character array..it works perfectly fine most of the times. It...
5
by: rawCoder | last post by:
Hi All, In Visual Basic .NET , your function definition might requirre you to return a value but (accidently/intentionally) you dont put any 'return value' in the function. In this case VB...
11
by: Charles Sullivan | last post by:
I have a number of functions, e.g.: int funct1( int arg1, int arg2, int arg3 ); int funct2( int arg1, int arg2, int arg3 ); int funct3( int arg1, int arg2, int arg3 ); that are called via...
6
by: tropos | last post by:
For my sins, I'm maintaining some old C code which is migrated to C++. Dozens of lines of it looks like this: char *cfd_THE_ts_result_sql= "select TRADE_DATE , VALUE , " " from (" " select...
3
by: gil | last post by:
Hi, I'm trying to find the best way to work with compiler warnings. I'd like to remove *all* warnings from the code, and playing around with the warning level, I've noticed that compiling with...
3
by: Peted | last post by:
Hi Im using vs2008 c# 3.0 and am going through some other person(s) code to clean up compiler warnings that are bieng produced. I have this code (at bottom) where a delegate/event is...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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...

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.