(defmacro interactive-try
  "If expr results in an exception, prompt the user to retry or give
up. The user can execute arbitrary code somewhere else or fiddle with
a DB before retrying. Returns nil if the user gives up."
  [expr]
  `(try
     ~expr
     (catch Exception e#
       (-> (ui/dialog :option-type :yes-no 
                      :resizable? false
                      :content (str "An exception occurred:\n"
                                    e#
                                    "\n\nRetry this step?\n"
                                    '~expr)
                      :title "Retry?"
                      :success-fn (fn [_#] *(interactive-try ~expr)*)
                      :no-fn (fn [_#] nil))
           ui/pack! ui/show!))))

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to