This project has moved. For the latest updates, please go here.

Why not return a Null Object?

May 23, 2015 at 2:47 AM
Edited May 23, 2015 at 2:48 AM
Imagine this code...
Function checkIfTaskFolderExists(folder As String) As Boolean
    Dim taskService As New TaskService

    If taskService.GetFolder(folder) IsNot Nothing Then
        Return True
    Else
        Return False
    End If
End Function

If checkIfTaskFolderExists("myTaskFolder") = True Then
    debug.writeline("the task folder exists")
Else
    debug.writeline("the task folder doesn't exist")
End If
But it doesn't work, an exception is thrown instead if you check for a task folder that doesn't exist. I don't understand why you would throw an exception instead of returning a Null Object that you could then check with an InNot Nothing check.
Coordinator
May 25, 2015 at 11:24 PM
This wrapper attempts to map to the Microsoft base library wherever possible. This is one of those instances. Changing at this point, after almost a decade of a released product, would constitute a breaking change. I agree that the pattern you suggest is preferable.
Marked as answer by dahall on 9/1/2015 at 9:59 AM