SHOW:
|
|
- or go back to the newest paste.
| 1 | - | A macro that should work as a try-catch clause. It should take some argument/s and return a value or an exception. If the code opened something it should be closed in the finally clause. |
| 1 | + | ;A macro that should work as a try-catch clause. It should take some argument/s and return a value or an ;exception. If the code opened something it should be closed in the finally clause. |
| 2 | ||
| 3 | - | PROBLEM: (def v (try_catch [s (FileReader. (File "C:/text.txt"))] (. s read))) |
| 3 | + | ;PROBLEM: (def v (try_catch [s (FileReader. (File "C:/text.txt"))] (. s read))) |
| 4 | CompilerException java.lang.RuntimeException: Unable to resolve symbol: s in this context, compiling:(NO_SOURCE_PATH:1:58) | |
| 5 | ||
| 6 | (defmacro try_catch [bindings & code] | |
| 7 | (if (list? bindings) | |
| 8 | `(try | |
| 9 | ~bindings | |
| 10 | (catch Throwable e# e#)) | |
| 11 | ||
| 12 | `(try | |
| 13 | ~code | |
| 14 | (catch Throwable e# e#) | |
| 15 | (finally (. ~@code close))))) |