mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-08 06:44:27 +00:00
docs: add documentation about return stm in the defer method
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
This commit is contained in:
parent
f3517a1aa6
commit
8328f5ed51
1 changed files with 13 additions and 0 deletions
|
|
@ -4813,6 +4813,19 @@ fn deferErrorExample(is_error: bool) !void {
|
||||||
print("encountered an error!\n", .{});
|
print("encountered an error!\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// inside a defer method the return statement
|
||||||
|
// is not allowed.
|
||||||
|
// The following lines produce the following
|
||||||
|
// error if uncomment
|
||||||
|
// ```
|
||||||
|
// defer.zig:73:9: error: cannot return from defer expression
|
||||||
|
// return error.DeferError;
|
||||||
|
// ```
|
||||||
|
//
|
||||||
|
//defer {
|
||||||
|
// return error.DeferError;
|
||||||
|
//}
|
||||||
|
|
||||||
if (is_error) {
|
if (is_error) {
|
||||||
return error.DeferError;
|
return error.DeferError;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue