#how to compare error set
1 messages · Page 1 of 1 (latest)
err, well it can only return AccessError, so
std.fs.cwd.access("...", .{}) catch {
...
};
that will not work as access function itself return void
std.fs.cwd().access("...", .{}) catch false
What do you want to do with that false
I want to get true only if access return any error
But you said you wanted a block that runs on error, not a bool to store in a variable
ok ok, lets simplify my question
I want to check if an error is part of AccessError error set
Why do you want this?
Are you trying to just detect an error, or are you trying to detect specifically all the errors in std.os.AccessError from a function that can return more than just those errors
detecting any error from AccessError
any error at all
returning from access function
And what do you want to do if there is an error?
the if condition should be true then
So you want to do one thing if there's an error, and something else if there isn't? Or you just want to run some code when there's an error and then continue?
For the former, use this form: ```rs
if (std.fs.cwd().access("...", .{})) |_| {
// code to run on success
} else |err| {
// code to run on error; err contains the error value
}
For the latter, use `catch` instead of `if`: ```rs
std.fs.cwd().access("...", .{}) catch |err| {
// code to run on error; `err` contains the error value
};
// code that runs regardless of if the function errored or not
If you really absolutely definitely want a boolean value (you almost certainly do not), you can use std.meta.isError
perfect, both last 2 solutions are exactly what I was searching for