Enhanced throw and catch for Clojure with support for throwing any object and flexible catch selectors.
Slingshot is a Clojure library that provides enhanced `try+` and `throw+` macros for more flexible exception handling. It allows developers to throw any Java object (not just `Throwable` instances) and catch exceptions using versatile selectors like class names, key-value vectors, or predicates. This solves the problem of rigid exception handling in Clojure by leveraging the language's features for more expressive error management.
Clojure developers who need more flexible exception handling beyond standard `try`/`catch`, particularly those working with complex error states or integrating with Java code.
Developers choose Slingshot because it offers full compatibility with Clojure and Java's native exception handling while adding powerful features like throwing arbitrary objects, destructuring in catch clauses, and accessing throw context. Its unique selling point is making exception handling more idiomatic to Clojure without sacrificing interoperability.
Enhanced try and throw for Clojure leveraging Clojure's capabilities
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Allows throwing Clojure maps or records as exceptions without needing `gen-class`, making custom exceptions more idiomatic, as shown in the example where `throw+` throws a map with `:type ::bad-tree`.
Catch clauses can match based on class names, key-value vectors, predicates, or custom forms, enabling precise exception handling, such as catching `[:type :tensor.parse/bad-tree]` in the usage example.
The binding in catch clauses supports destructuring, allowing easy access to contents of thrown collections, like `{:keys [tree hint]}` in the sample code to extract data directly.
Provides access to throw site context via `&throw-context`, including message, cause, and stack trace, enhancing debugging, as detailed in the README's description of the context map.
Wrapping non-Throwable objects in `Throwable` wrappers via `ex-info` adds layers that might impact performance in high-throughput scenarios, as acknowledged in the handling of nested wrappers.
Requires adding an external library for functionality that could be handled with standard Clojure, increasing project complexity and potential dependency management issues.
As a niche library for Clojure exception handling, it has a smaller community and fewer integrations compared to mainstream Clojure tools, which might affect long-term support and resources.