Exceptions are slow - is there a better way to test for valid objects?

D

David Berman

#1 - Is it just me or is catching an exception a very slooow thing?

#2 - Sometimes using certain API's you don't know if you have a valid
object or not, at least, I don't know how to test it. Sometimes for
example I'll do something like this:
if (excel_range.value2 != null)
DoSomethingWith(excel_range.value2)

and I'll get an exception indicating that I'm trying to use something
that isn't a reference to an object or that type of error. So, to see
if I got a valid excel_range, I basically have to test it by referencing
it in a try / catch block. This makes my program crawl. Isn't there a
better way to test for this sort of thing?

Thank you!
Neophyte C# developer Dave



Meet people for friendship, contacts,
or romance using free instant messaging software! See a picture you
like? Click once for a private conversation with that person!

www.SEN.us
 
P

Pat Cantey III

if (excel_range.value2 != null)
DoSomethingWith(excel_range.value2)

Dave,

How about:

if (excel_range != null){
if(excel_range.value2 !=null)
DoSomethingWith(excel_range.value2)
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top