Welcome! Please see the About page for a little more info on how this works.

0 votes
in Clojure by
We often use 'ex-info' to throw a custom exception.But ex-info at least accepts two arguments: a string message and a data map.
In most cases,but we don't need to throw a exception that taken a data map.
So i think we can add a new arity to ex-info:

  (ex-info "the exception message")

That created a ExceptionInfo instance carries empty data.

I am not sure it's useful for other people,but it's really useful for our developers.

The patch is attached.

7 Answers

0 votes
by

Comment made by: alexmiller

Why "(. clojure.lang.PersistentArrayMap EMPTY)" ? Why not just {}?

0 votes
by

Comment made by: lgs32a

I always thought the lack of a one-arity was intentional design to make users use the map argument. Why do you want to throw ExceptionInfos with no data?

0 votes
by

Comment made by: killme2008

@Alex I forgot why i used EMPTY map here, maybe influenced by the code https://github.com/clojure/clojure/blob/7aad2f7dbb3a66019e5cef3726d52d721e9c60df/src/clj/clojure/core.clj#L4336

@Leon For example, throw an exception when arguments error:

(when-not (integer? c)
(throw (ex-info "Expect number for c."))

We don't need data here.

0 votes
by

Comment made by: bronsa

Then why not just throw an (Exception. "expect number for c")? I don't see the added value in throwing exinfos w/o data vs just throwing an Exception

0 votes
by

Comment made by: killme2008

Indeed, it was just a technical decision that we chose to use ex-info for throwing exceptions.

0 votes
by

Comment made by: duke

This would be a nice way to throw simple exceptions from cljc files that works in both clj and cljs.

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-1496 (reported by killme2008)
...