mirror of
https://github.com/ziglang/zig.git
synced 2024-11-26 23:22:44 +00:00
20 lines
437 B
Zig
20 lines
437 B
Zig
const std = @import("std");
|
|
|
|
fn captureError(captured: *?anyerror) !void {
|
|
errdefer |err| {
|
|
captured.* = err;
|
|
}
|
|
return error.GeneralFailure;
|
|
}
|
|
|
|
test "errdefer capture" {
|
|
var captured: ?anyerror = null;
|
|
|
|
if (captureError(&captured)) unreachable else |err| {
|
|
try std.testing.expectEqual(error.GeneralFailure, captured.?);
|
|
try std.testing.expectEqual(error.GeneralFailure, err);
|
|
}
|
|
}
|
|
|
|
// test
|