diff options
author | jjanzen <jjanzen@jjanzen.ca> | 2025-01-22 10:04:04 -0600 |
---|---|---|
committer | jjanzen <jjanzen@jjanzen.ca> | 2025-01-22 10:04:04 -0600 |
commit | 4438558931d634704b1f8d4af698afca3b5c4a1b (patch) | |
tree | 19d35be819c463041a8de2c961ec3106fce187f7 /src/main.zig | |
parent | b7d602f885f992d00ad1ca7d9040782920931293 (diff) |
handle errors
Diffstat (limited to 'src/main.zig')
-rw-r--r-- | src/main.zig | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/main.zig b/src/main.zig index 6816231..98f0369 100644 --- a/src/main.zig +++ b/src/main.zig @@ -11,24 +11,28 @@ pub fn main() u8 { }; defer io.deinit(); - io.displayMessage("Initialized"); + try io.displayMessage("Initialized"); var action = Action.illegal; var tick_count: usize = 0; while (action != Action.exit) { - var str = std.fmt.allocPrintZ(allocator, "{}", .{tick_count}) catch { + const str = std.fmt.allocPrint(allocator, "{}", .{tick_count}) catch { + return 1; + }; + defer allocator.free(str); + try io.displayMessage(str); + + action = io.waitForTick() catch { return 1; }; - io.displayMessage(str); - allocator.free(str); - action = io.waitForTick(); switch (action) { Action.tick => { - str = std.fmt.allocPrintZ(allocator, "{}", .{tick_count}) catch { + const str2 = std.fmt.allocPrint(allocator, "{}", .{tick_count}) catch { return 1; }; - io.displayMessage(str); - allocator.free(str); + defer allocator.free(str2); + try io.displayMessage(str2); + tick_count += 1; }, else => {}, |