aboutsummaryrefslogtreecommitdiff
path: root/21_errors.zig
diff options
context:
space:
mode:
authorDave Gauer <dave@ratfactor.com>2021-02-09 18:36:57 -0500
committerDave Gauer <dave@ratfactor.com>2021-02-09 18:36:57 -0500
commit55ad7c32f2d534b1fbd438204d21738f958c51a5 (patch)
tree16be4b53193105a759b3eec25be5e664d41c428d /21_errors.zig
parentcf0920de31e9b5f3c5ba6de19a1b4c8d0c58b907 (diff)
downloadziglings-55ad7c32f2d534b1fbd438204d21738f958c51a5.tar.gz
ziglings-55ad7c32f2d534b1fbd438204d21738f958c51a5.tar.bz2
ziglings-55ad7c32f2d534b1fbd438204d21738f958c51a5.tar.xz
ziglings-55ad7c32f2d534b1fbd438204d21738f958c51a5.zip
Moved exercises to exercises because exercises
Diffstat (limited to '21_errors.zig')
-rw-r--r--21_errors.zig46
1 files changed, 0 insertions, 46 deletions
diff --git a/21_errors.zig b/21_errors.zig
deleted file mode 100644
index 34c5e18..0000000
--- a/21_errors.zig
+++ /dev/null
@@ -1,46 +0,0 @@
-//
-// Believe it or not, sometimes things to wrong in programs.
-//
-// In Zig, an error is a value. Errors are named so we can identify
-// things that can go wrong. Errors are created in "error sets", which
-// are just a collection of named errors.
-//
-// We have the start of an error set, but we're missing the condition
-// "TooSmall". Please add it where needed!
-const MyNumberError = error{
- TooBig,
- ???,
- TooFour,
-};
-
-const std = @import("std");
-
-pub fn main() void {
- var nums = [_]u8{2,3,4,5,6};
-
- for (nums) |n| {
- std.debug.print("{}", .{n});
-
- const number_error = numberFail(n);
-
- if (number_error == MyNumberError.TooBig) {
- std.debug.print(">4. ", .{});
- }
- if (???) {
- std.debug.print("<4. ", .{});
- }
- if (number_error == MyNumberError.TooFour) {
- std.debug.print("=4. ", .{});
- }
- }
-
- std.debug.print("\n", .{});
-}
-
-// Notice how this function can return any member of the MyNumberError
-// error set.
-fn numberFail(n: u8) MyNumberError {
- if(n > 4) return MyNumberError.TooBig;
- if(n < 4) return MyNumberError.TooSmall; // <---- this one is free!
- return MyNumberError.TooFour;
-}