mirror of
https://github.com/ziglang/zig.git
synced 2025-12-10 00:03:10 +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
@ -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…
x
Reference in New Issue
Block a user