Re: Code Standard 2.0 new objects outside of Try Block



Thanks --- I'll follow that advice.

I was thinking in 1.1 that only class member variables were't
initialized. I'll run it through the debugger to verify, but I'll Null
them anyway to satisfy the compiler.

Kevin Spencer wrote:
I do this too - set the variables to null.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Accept the Unexpected.

"Siva M" <shiva_sm@xxxxxxxxxxxxxxxxx> wrote in message
news:O7HXzT8uGHA.5056@xxxxxxxxxxxxxxxxxxxxxxx
Gabe,

Just assign null to the variables - this should stop those warnings. You
don't necessarily have to instantiate the objects.

"gabe" <gabedog@xxxxxxxxx> wrote in message
news:1155134537.290769.36560@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I have question about code standards in VS 2005

I have been declaring objects before a try block in case I would ever
want to refer to them in 'Catch' block. When I converted my apps to 2.0
I get warnings that objects have been declared, but not initialized.
I've hesitated to actually 'New' an object outside of a try in the
event of an exception occurring. For example, if I new up a Connection
object with a connection string with an incorrect syntax it will throw
an InvalidArgument exception.

What's a best practice for this?

(I don't use Try Blocks in every method, but when I do, I want to make
sure that things are being trapped)

Thanks,

Gabe


.



Relevant Pages

  • Re: Code Standard 2.0 new objects outside of Try Block
    ... Just assign null to the variables - this should stop those warnings. ... I have been declaring objects before a try block in case I would ever ... object with a connection string with an incorrect syntax it will throw ... an InvalidArgument exception. ...
    (microsoft.public.dotnet.general)
  • Re: Code Standard 2.0 new objects outside of Try Block
    ... I have been declaring objects before a try block in case I would ever ... I get warnings that objects have been declared, ... object with a connection string with an incorrect syntax it will throw ... an InvalidArgument exception. ...
    (microsoft.public.dotnet.general)
  • Re: Code Standard 2.0 new objects outside of Try Block
    ... Warnings are just that, they don't necessarily mean the code is going to crash. ... I have been declaring objects before a try block in case I would ever ... object with a connection string with an incorrect syntax it will throw ... an InvalidArgument exception. ...
    (microsoft.public.dotnet.general)
  • Code Standard 2.0 new objects outside of Try Block
    ... I have been declaring objects before a try block in case I would ever ... want to refer to them in 'Catch' block. ... object with a connection string with an incorrect syntax it will throw ... an InvalidArgument exception. ...
    (microsoft.public.dotnet.general)

Loading