Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2d453d3

Browse files
author
Rafael Cunha de Almeida
committedDec 7, 2014
Using exceptions (just for kicks)
1 parent 0da1244 commit 2d453d3

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed
 

‎Nsteps.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public class Nsteps {
44
public static long CoordsToNumber(long x, long y) {
55
if (y != (x-2) && y != x) {
6-
return -1;
6+
throw new ArgumentOutOfRangeException();
77
}
88
if (x % 2 == 0) {
99
return x + y;
@@ -16,11 +16,11 @@ public static void Main() {
1616
int lines = Convert.ToInt32(Console.ReadLine());
1717
while (lines-- > 0) {
1818
string[] tuple = Console.ReadLine().Split(' ');
19-
long number = CoordsToNumber(Convert.ToInt64(tuple[0]), Convert.ToInt64(tuple[1]));
20-
if (number < 0) {
21-
Console.WriteLine("No Number");
22-
} else {
19+
try {
20+
long number = CoordsToNumber(Convert.ToInt64(tuple[0]), Convert.ToInt64(tuple[1]));
2321
Console.WriteLine(number);
22+
} catch (ArgumentOutOfRangeException) {
23+
Console.WriteLine("No Number");
2424
}
2525
}
2626
}

0 commit comments

Comments
 (0)
Please sign in to comment.