When working with objects you're not sure are null or not, what is the best practice?
object o = SomeMethodReturningAnObjectOrNull();
Is it better to check o
like this:
if (o != null)
{
//do something usefull
}
Or to make a try catch:
try
{
//do something usefull
}
catch (NullReferenceException)
{
}
If it depends on the situation, what is the advantage of one or the other?