3 ms·
why not just put all that into a function, and at the callsite just use a `try` ? that should work fn do_foo(allocator: std.mem.Allocator, ...) ... { ... }
by signa11 4y ago
why not just put all that into a function, and at the callsite just use a `try` ? that should work
fn do_foo(allocator: std.mem.Allocator, ...) ... { ... }
const do_foo_ret = try do_foo(...)
so there is only 1 `try` instance...
- eatonphil 4y agoYou can't not `try` or `catch`. So if you made a separate function you'd just be doing all of those `try`-es line by line in that other function. const std = @import("std"); fn thing(a: std.mem.Allocator) !void { std.fmt.allocPrint(a, "", .{}); } pub fn main() !void { var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); defer arena.deinit(); const allocator = arena.allocator(); try thing(allocator); } Running `zig build-exe test.zig`: test.zig:4:23: error: error is ignored std.fmt.allocPrint(a, "", .{}); ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~ test.zig:4:23: note: consider using 'try', 'catch', or 'if' referenced by: main: test.zig:12:9 callMain: /home/phil/vendor/zig-linux-x86_64-0.11.0-dev.2213+515e1c93e/lib/std/start.zig:617:32 remaining reference traces hidden; use '-freference-trace' to see all reference traces I'll add this to the post.
- deleted 4y ago[deleted]