Link to home
Start Free TrialLog in
Avatar of Dale Burrell
Dale BurrellFlag for New Zealand

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of itsmeandnobodyelse
itsmeandnobodyelse
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dale Burrell

ASKER

C# is as follows - cheers
#pragma warning disable 0168
        catch (ThreadAbortException Error)
        {
            LogError("Maintenance:Thread - Stopped");
        }
        #pragma warning restore 0168

Open in new window

Avatar of Zoppo
BTW, I think you can simply solve this by leaving out a variable name, i.e.:

> catch (ThreadAbortException)
Doh! How silly I didn't even think to try that - works a treat - sorry can't give you any points :(
No problem ...
>>>> sorry can't give you any points :(

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

Regards, Alex
IMO there's no need to, it's not worth the effort ...