Click here to Skip to main content
Sign Up to vote bad
good
Hi all,
 
I have a small problem. The thing is, how to handle a NullReferenceException when accessing foreign key classes, in other words, check if the foreign key instance is null before calling / using it. For example:
 
Mammal.Human.FirstName - Where Human will be null. But I don't want to perform a null check for each foreign key class. For example: Mammal.Dog.Age (now Dog could be null).
 
Many thanks in advance!
Kind regards,
Posted 13 Jun '12 - 23:03
Programm3r10.6K


1 solution

I think there are two options. 1) if you have access to the classes code then you might want to return a string that suggests a null, e.g. "NOTFOUND".
2) You really don't have any other option other than to do a null check.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 333
1 OriginalGriff 261
2 Mohammed Hameed 198
3 Mayur_Panchal 153
4 Dave Kreskowiak 125
0 Sergey Alexandrovich Kryukov 8,171
1 OriginalGriff 6,236
2 CPallini 3,482
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 14 Jun 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid