mirror of
https://github.com/ziglang/zig.git
synced 2025-12-09 15:53:08 +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", .{});
|
||||
}
|
||||
|
||||
// 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) {
|
||||
return error.DeferError;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user