G
Guest
I have created a class with the following constructor:
Public Sub New(ByVal ID As Integer)
'Use ID to get info from data store and set all properties
End Sub
I need to somehow handle an invalid ID being passed to the constructor. By
invalid, I mean one that does not have an associated record in the data
store. I believe that throwing an exception would be the best way to handle
this, but am not sure. After reading quite a few articles it seems exceptions
should only be used when you don't expect something to happen, but yet it is
still possible. Theoretically this constructor should never be passed an
invalid ID, but it's definitely possible. I have also read that it is good
practice to derive my own custom Exception class from ApplicationException. I
was thinking about making a "NoMatchingRecordFoundException" class. Any help
would be appreciated. Also, if I do start creating these custom exceptiions
what is the best way to do this so I can implement them in all of my projects?
Public Sub New(ByVal ID As Integer)
'Use ID to get info from data store and set all properties
End Sub
I need to somehow handle an invalid ID being passed to the constructor. By
invalid, I mean one that does not have an associated record in the data
store. I believe that throwing an exception would be the best way to handle
this, but am not sure. After reading quite a few articles it seems exceptions
should only be used when you don't expect something to happen, but yet it is
still possible. Theoretically this constructor should never be passed an
invalid ID, but it's definitely possible. I have also read that it is good
practice to derive my own custom Exception class from ApplicationException. I
was thinking about making a "NoMatchingRecordFoundException" class. Any help
would be appreciated. Also, if I do start creating these custom exceptiions
what is the best way to do this so I can implement them in all of my projects?