Created
January 24, 2011 15:07
-
-
Save rwat/793340 to your computer and use it in GitHub Desktop.
exception handling example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns my-ns | |
(:use [clj-time.core :only [date-time]])) | |
(defn my-date-time | |
"same as clj-time.core date-time but returns nil on improper input" | |
[& args] | |
(try | |
(apply date-time (map #(Integer/parseInt %) args)) | |
(catch RuntimeException e nil))) | |
; returns a clj-time.core date-time | |
(println (my-date-time "2011" "01" "01")) | |
; returns nil | |
(println (my-date-time "2011" "asdf" "01")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment