From 5159a335ad7494a7f459745b86d07148b57bb57c Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Wed, 25 Sep 2019 23:28:32 +0200 Subject: [PATCH] upgrade sci for try/catch, add exception bindings (#75) --- sci | 2 +- src/babashka/impl/exceptions.clj | 7 +++++++ src/babashka/main.clj | 4 +++- test/babashka/main_test.clj | 3 +++ 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 src/babashka/impl/exceptions.clj diff --git a/sci b/sci index 095e66ed..c1a70167 160000 --- a/sci +++ b/sci @@ -1 +1 @@ -Subproject commit 095e66ed99b57089f1478bd17ae2f23710273867 +Subproject commit c1a70167bed16004b5cd57add028215184a4f708 diff --git a/src/babashka/impl/exceptions.clj b/src/babashka/impl/exceptions.clj new file mode 100644 index 00000000..d36adf61 --- /dev/null +++ b/src/babashka/impl/exceptions.clj @@ -0,0 +1,7 @@ +(ns babashka.impl.exceptions) + +(def exception-bindings + {'Exception Exception + 'java.lang.Exception Exception + 'ArithmeticException ArithmeticException + 'java.lang.ArithmeticException ArithmeticException}) diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 8b664696..031310c1 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -13,6 +13,7 @@ [babashka.impl.pipe-signal-handler :refer [handle-pipe! pipe-signal-received?]] [babashka.impl.socket-repl :as socket-repl] [babashka.impl.tools.cli :refer [tools-cli-namespace]] + [babashka.impl.exceptions :refer [exception-bindings]] [babashka.net :as net] [clojure.edn :as edn] [clojure.java.io :as io] @@ -146,7 +147,8 @@ Everything after that is bound to *command-line-args*.")) system-bindings file-bindings thread-bindings - integer-bindings)) + integer-bindings + exception-bindings)) (defn read-edn [] (edn/read {;;:readers *data-readers* diff --git a/test/babashka/main_test.clj b/test/babashka/main_test.clj index 546d5872..e23baca6 100644 --- a/test/babashka/main_test.clj +++ b/test/babashka/main_test.clj @@ -188,3 +188,6 @@ (deftest tools-cli-test (is (= {:result 8080} (bb nil "test/babashka/scripts/tools.cli.bb")))) + +(deftest try-catch-test + (is (zero? (bb nil "(try (/ 1 0) (catch ArithmeticException _ 0))"))))