221V 1 week ago
parent
commit
ae6c34386e
1 changed files with 20 additions and 19 deletions
  1. 20 19
      exercises/025_errors5.zig

+ 20 - 19
exercises/025_errors5.zig

@@ -10,29 +10,30 @@
 const std = @import("std");
 const std = @import("std");
 
 
 const MyNumberError = error{
 const MyNumberError = error{
-    TooSmall,
-    TooBig,
+  TooSmall,
+  TooBig,
 };
 };
 
 
-pub fn main() void {
-    const a: u32 = addFive(44) catch 0;
-    const b: u32 = addFive(14) catch 0;
-    const c: u32 = addFive(4) catch 0;
-
-    std.debug.print("a={}, b={}, c={}\n", .{ a, b, c });
+pub fn main() void{
+  const a: u32 = addFive(44) catch 0;
+  const b: u32 = addFive(14) catch 0;
+  const c: u32 = addFive(4) catch 0;
+  
+  std.debug.print("a={}, b={}, c={}\n", .{ a, b, c });
 }
 }
 
 
-fn addFive(n: u32) MyNumberError!u32 {
-    // This function needs to return any error which might come back from detect().
-    // Please use a "try" statement rather than a "catch".
-    //
-    const x = detect(n);
-
-    return x + 5;
+fn addFive(n: u32) MyNumberError!u32{
+  // This function needs to return any error which might come back from detect().
+  // Please use a "try" statement rather than a "catch".
+  //
+  const x = try detect(n);
+  
+  return x + 5;
 }
 }
 
 
-fn detect(n: u32) MyNumberError!u32 {
-    if (n < 10) return MyNumberError.TooSmall;
-    if (n > 20) return MyNumberError.TooBig;
-    return n;
+fn detect(n: u32) MyNumberError!u32{
+  if(n < 10){ return MyNumberError.TooSmall; }
+  if(n > 20){ return MyNumberError.TooBig; }
+  return n;
 }
 }
+