Skip to content

Instantly share code, notes, and snippets.

@Techcable
Created May 3, 2022 05:41
Show Gist options
  • Save Techcable/88808f0ff219e22f6bfd02ce1dbae0d9 to your computer and use it in GitHub Desktop.
Save Techcable/88808f0ff219e22f6bfd02ce1dbae0d9 to your computer and use it in GitHub Desktop.
Error stall with Error!noreturn
const ExampleError = error { Foo };
fn error_helper(e: ExampleError) ExampleError!noreturn {
return e;
}
fn other_func(i: i64) ExampleError!*i64 {
if (@mod(i, 2) == 0) {
return @divTrunc(i, 2);
} else {
return ExampleError.Foo;
}
}
export fn bar(i: i64) ?*i64 {
return other_func(i) catch |e| {
error_helper(e) catch return null;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment