Racket directory-exists? Handlers

Today I experimented with how to handle Racket’s directory-exists? exception thrown when the empty string is passed:

(define (isdir? dir)
(cond
[(with-handlers ([exn:fail:filesystem?
(λ (x) #f)]
[exn:fail?
(λ (x) #f)]
)
(directory-exists? dir))]
[1]))

(isdir? “”)

Leave a Reply

Your email address will not be published. Required fields are marked *