Skip to main content

Crate handle_this

Crate handle_this 

Source
Expand description

handle-this - Ergonomic error handling with try/catch/throw/inspect/finally

§Overview

handle-this provides composable error handling with automatic stack traces. All invocations return Result<T> - no hidden control flow.

§Quick Start

use handle_this::{handle, Result};

fn load_data(path: &str) -> Result<String> {
    handle!{ try { std::fs::read_to_string(path)? } with "reading" }
}

§Patterns

§Basic

PatternDescription
try { }Execute, wrap error with trace
try { } catch e { }Recover from error
try { } catch Type(e) { }Recover only specific type
try { } catch Type(e) { } else { }Typed catch with fallback
try { } try catch e { }Fallible recovery (body returns Result)
try { } throw e { }Transform error
try { } throw Type(e) { }Transform only specific type
try { } inspect e { }Side effect, then propagate
try { } finally { }Cleanup always runs
try -> T { } else { }Infallible (returns T, not Result)

§Guards

PatternDescription
catch e when cond { }Conditional catch
catch Type(e) when cond { }Typed with guard
throw e when cond { }Conditional transform
catch Type(e) match expr { arms }Match on error value
PatternDescription
catch any Type(e) { }First matching error in cause chain
catch all Type |errs| { }All matching errors as Vec

§Context

PatternDescription
try { } with "message"Add context message
try { } with { key: val }Add structured data
try { } with "msg", { key: val }Both message and data
scope "name", try { }Hierarchical scope
require cond else "msg", try { }Precondition check

§Chaining

PatternDescription
try { a()? }, then |x| { b(x)? }Chain operations

§Iteration

PatternDescription
try for x in iter { }First success
try any x in iter { }Alias for try for
try all x in iter { }Collect all results
try while cond { }Retry loop

§Async

PatternDescription
async try { }Async version (all patterns supported)

Modules§

result
Result module for try catch blocks.

Macros§

handle
Main error handling macro.

Structs§

Error
Type-erased error wrapper for when you don’t need to preserve the concrete type.
FrameView
View into a single frame of the error trace.
Handled
Error wrapper that captures context and stack traces for any error.
StringError

Enums§

Value
A typed value for structured logging attachments.

Traits§

HandleExt
Extension trait for adding context to Result<T, Handled>.
IntoValue
Trait for converting types into Value.

Type Aliases§

Result
Result type alias.