Clojure

Added a new arity to 'ex-info' that only accepts a message.

Details

  • Type: Feature Feature
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: Release 1.7
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Environment:
    java version "1.7.0_17"
    Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
    Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

    Mac OSX 10.9.4
  • Approval:
    Triaged

Description

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.

Activity

Hide
Alex Miller added a comment -

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

Show
Alex Miller added a comment - Why "(. clojure.lang.PersistentArrayMap EMPTY)" ? Why not just {}?
Hide
Leon Grapenthin added a comment -

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?

Show
Leon Grapenthin added a comment - 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?
Hide
dennis zhuang added a comment -

@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.

Show
dennis zhuang added a comment - @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.
Hide
Nicola Mometto added a comment -

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

Show
Nicola Mometto added a comment - 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
Hide
dennis zhuang added a comment -

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

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

People

Vote (2)
Watch (2)

Dates

  • Created:
    Updated: