VWDEE 2008 - How to Hide - The variable is declared but never used

When I use a try/catch block to handle specific errors I often don't need to make use of the error variable - but then I get a warning "The variable is declared but never used". Is there anyway to remove this warning in this specific circumstance? See code for example...
// gives warning "warning CS0168: The variable 'Error' is declared but never used"

catch (ThreadAbortException Error)
{
    // The error type itself tells me everything I need to know, meaning I don't need to inspect the variable 'Error' - so how to hide the warning in this case?
    LogError("Maintenance:Thread - Stopped");
}

Open in new window

LVL 21
Dale BurrellDirectorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

itsmeandnobodyelseCommented:
>>>> Is there anyway to remove this warning in this specific circumstance?

I think yes,  though I don't know for sure that C# error levels and preprocessing is identically to VC++ whre you would have the following possibilities:

First, you could reduce the warning level to 3. Then warnings of level wouldn't show.

Second is to add a

#pragma warning (disable : 0168)

above the code. After the statement you can reenable it by

#pragma warning (enable : 0168)


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dale BurrellDirectorAuthor Commented:
C# is as follows - cheers
#pragma warning disable 0168
        catch (ThreadAbortException Error)
        {
            LogError("Maintenance:Thread - Stopped");
        }
        #pragma warning restore 0168

Open in new window

0
ZoppoCommented:
BTW, I think you can simply solve this by leaving out a variable name, i.e.:

> catch (ThreadAbortException)
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Dale BurrellDirectorAuthor Commented:
Doh! How silly I didn't even think to try that - works a treat - sorry can't give you any points :(
0
ZoppoCommented:
No problem ...
0
itsmeandnobodyelseCommented:
>>>> sorry can't give you any points :(

You could use the 'Request Attention' button above and let a Moderator reopen the question.

Regards, Alex
0
ZoppoCommented:
IMO there's no need to, it's not worth the effort ...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.