diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-01-23 23:08:09 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-01-23 23:08:09 -0500 |
| commit | b3a6faf13ebccb82bb5fa82012bb62699a8ff6fb (patch) | |
| tree | c0daed782354e52721845e87ecb62ef491ec70d7 /doc/langref.html.in | |
| parent | ad2527d47af6b6f22e0e9d127417a30c50b69c35 (diff) | |
| download | zig-b3a6faf13ebccb82bb5fa82012bb62699a8ff6fb.tar.gz zig-b3a6faf13ebccb82bb5fa82012bb62699a8ff6fb.zip | |
replace %defer with errdefer
See #632
now we have 1 less sigil
Diffstat (limited to 'doc/langref.html.in')
| -rw-r--r-- | doc/langref.html.in | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/doc/langref.html.in b/doc/langref.html.in index 3734d9ff75..601b53463f 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -2533,7 +2533,7 @@ test "defer unwinding" { deferUnwindExample(); } -// The %defer keyword is similar to defer, but will only execute if the +// The errdefer keyword is similar to defer, but will only execute if the // scope returns with an error. // // This is especially useful in allowing a function to clean up properly @@ -2547,7 +2547,7 @@ fn deferErrorExample(is_error: bool) -> %void { warn("end of function\n"); } - %defer { + errdefer { warn("encountered an error!\n"); } @@ -2556,7 +2556,7 @@ fn deferErrorExample(is_error: bool) -> %void { } } -test "%defer unwinding" { +test "errdefer unwinding" { _ = deferErrorExample(false); _ = deferErrorExample(true); } @@ -2922,7 +2922,7 @@ fn doAThing(str: []u8) { {#code_end#} <p> The other component to error handling is defer statements. - In addition to an unconditional <code>defer</code>, Zig has <code>%defer</code>, + In addition to an unconditional <code>defer</code>, Zig has <code>errdefer</code>, which evaluates the deferred expression on block exit path if and only if the function returned with an error from the block. </p> @@ -2934,7 +2934,7 @@ fn createFoo(param: i32) -> %Foo { const foo = try tryToAllocateFoo(); // now we have allocated foo. we need to free it if the function fails. // but we want to return it if the function succeeds. - %defer deallocateFoo(foo); + errdefer deallocateFoo(foo); const tmp_buf = allocateTmpBuffer() ?? return error.OutOfMemory; // tmp_buf is truly a temporary resource, and we for sure want to clean it up @@ -2943,7 +2943,7 @@ fn createFoo(param: i32) -> %Foo { if (param > 1337) return error.InvalidParam; - // here the %defer will not run since we're returning success from the function. + // here the errdefer will not run since we're returning success from the function. // but the defer will run! return foo; } @@ -5619,7 +5619,7 @@ TryExpression = "try" Expression BreakExpression = "break" option(":" Symbol) option(Expression) -Defer(body) = option("%") "defer" body +Defer(body) = ("defer" | "deferror") body IfExpression(body) = "if" "(" Expression ")" body option("else" BlockExpression(body)) |
