Why not return a Null Object?

May 23, 2015 at 1:47 AM
Edited May 23, 2015 at 1: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
        Return False
    End If
End Function

If checkIfTaskFolderExists("myTaskFolder") = True Then
    debug.writeline("the task folder exists")
    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.
May 25, 2015 at 10: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