Skip to content

Instantly share code, notes, and snippets.

@raek
Created July 21, 2011 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raek/1098366 to your computer and use it in GitHub Desktop.
Save raek/1098366 to your computer and use it in GitHub Desktop.
safety net in interactive swing development
(ns se.raek.kerodon.debug
(:import (javax.swing JFrame JOptionPane JTextArea)))
(defn debug-frame [thing]
(doto (JFrame. "Debug Frame")
(.add thing)
(.pack)
(.show)))
(defn debug-message [msg]
(JOptionPane/showMessageDialog nil msg "Debug MEssage" JOptionPane/PLAIN_MESSAGE))
(defn debug-text [text]
(doto (JFrame. "Debug Text")
(.add (JTextArea. text))
(.pack)
(.show)))
(ns se.raek.kerodon.error
(:use se.raek.kerodon.debug))
(defn exception-text [^Throwable e]
(let [sw (java.io.StringWriter.)
pw (java.io.PrintWriter. sw)]
(.printStackTrace e pw)
(.toString sw)))
(defn handle-error [e]
(debug-text (exception-text e)))
(defmacro safety-net [& body]
`(try
~@body
(catch InterruptedException e#
(throw e#))
(catch Throwable e#
(handle-error e#))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment