Error

#load "std/error.bl"
_Error :: struct {
    msg: string;
    code: s32;
}

Error :: *_Error;

Universal error state representation used across the API.

Example

div :: fn (a: s32, b: s32) (s32, Error) {
    if b == 0 {
        // Return error with message.
        return 0, error("Divide by zero '%/%'!", a, b);
    }
    // Return result and OK state.
    return a / b, ok();
}

main :: fn () s32 {
    loop i := -5; i <= 5; i += 1 {
        result, error :: div(10, i);
        if is_ok(error) {
            print("Result is %.\n", result);
        } else {
            print("Error: %.\n", error);
        }
    }
    return 0;
}