Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Clojure
  3. slingshot

slingshot

Clojure

Enhanced throw and catch for Clojure with support for throwing any object and flexible catch selectors.

GitHubGitHub
652 stars29 forks0 contributors

What is slingshot?

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.

Target Audience

Clojure developers who need more flexible exception handling beyond standard `try`/`catch`, particularly those working with complex error states or integrating with Java code.

Value Proposition

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.

Overview

Enhanced try and throw for Clojure leveraging Clojure's capabilities

Use Cases

Best For

  • Throwing Clojure maps or records as exceptions without defining custom exception classes
  • Catching exceptions based on specific key-value pairs in thrown data structures
  • Destructuring caught exceptions directly in catch clauses for cleaner code
  • Accessing detailed throw context (message, cause, stack trace) within exception handlers
  • Handling non-Throwable objects in exception flows
  • Writing more expressive and flexible error handling in Clojure applications

Not Ideal For

  • Projects that strictly adhere to Java's exception handling standards without Clojure-specific extensions
  • Applications where minimal runtime overhead is critical, due to performance costs from wrapping non-Throwable objects
  • Teams seeking drop-in exception handling without learning new macros or patterns
  • Codebases heavily reliant on Java interop that prefer native `try`/`catch` for consistency and simplicity

Pros & Cons

Pros

Throw Any Object

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

Flexible Catch Selectors

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.

Destructuring Support

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.

Throw Context Access

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.

Cons

Performance Overhead

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.

Library Dependency

Requires adding an external library for functionality that could be handled with standard Clojure, increasing project complexity and potential dependency management issues.

Limited Ecosystem

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.

Frequently Asked Questions

Quick Stats

Stars652
Forks29
Contributors0
Open Issues11
Last commit6 years ago
CreatedSince 2011

Tags

#java-interop#functional-programming#macros#clojure-library#error-handling#clojure#exception-handling

Built With

C
Clojure

Included in

Clojure2.8k
Auto-fetched 2 hours ago

Related Projects

potemkinpotemkin

some ideas which are almost good

Stars592
Forks56
Last commit4 months ago
virgilvirgil

Recompile Java code without restarting the REPL

Stars356
Forks23
Last commit5 months ago
riddleyriddley

code-walking without caveats

Stars201
Forks30
Last commit4 months ago
clj-tupleclj-tuple

efficient small collections for clojure

Stars182
Forks17
Last commit11 years ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub