[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 969
  • Last Modified:

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

0
Dale Burrell
Asked:
Dale Burrell
  • 3
  • 2
  • 2
1 Solution
 
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
 
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
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
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

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now