Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

i've seen code that uses this alot and then some examples that don't use it at all... any good guidelines of when to use this error checking and when it's not needed?

 

should it be in every method... etc...

 

I did a search but couldn't find such a basic answer.

Posted
If you have a function where you think there is a remote possibility that it could throw an execption then 99% of the time you should use it. So the basic answer is yes.
"Who is John Galt?"
Posted
Every method in the .NET Framework that can throw an exception has that information detailed in the help system. Every method you call that can throw an exception is a candidate for a Try...Catch block. If your code is the only point of access for the objects you are using then in most cases you won't need to use exception handling because if your code is written properly then those exceptional circumstances won't occur. When you should definitely be using exception handling is when you are dealing with objects that can be affected by factors beyond your control, like connecting to a database.
Posted

and, of course, if within a method you instance a class that implements IDisposable, the last thing you should do is call dispose():

 

dim myDisposable as IDisposable = new MyDisposable ()

 

try

' use my disposable

finally

myDisposable.Dispose()

end try

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Posted

Of course, that means "The final thing you should do is call dispose" as when I read "The last thing you should do is call dispose" I panicked for a second - I *always* call dispose on disposable objects when I've finished with them!!!

 

B

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...