Created
July 21, 2011 22:13
-
-
Save raek/1098366 to your computer and use it in GitHub Desktop.
safety net in interactive swing development
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 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))) |
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 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