@aicacia/trycatch
    Preparing search index...

    @aicacia/trycatch

    ts-trycatch

    license docs npm (scoped) build

    typesafe go like tuple results for async and sync code

    import { trycatch } from "@aicacia/trycatch";

    const [numbers, err] = trycatch(() => {
    const numbers = [];
    for (let i = 0; i < 10; i++) {
    numbers.push(maybeWillThrow(i));
    }
    return numbers;
    });
    if (err) {
    // handle err
    }
    // use numbers
    import { trycatch } from "@aicacia/trycatch";

    const [numbers, err] = await trycatch(async () => {
    const numbers = [];
    for (let i = 0; i < 10; i++) {
    numbers.push(await maybeWillThrowAsync(i));
    }
    return numbers;
    });
    if (err) {
    // handle err
    }
    // use numbers