Skip to content

Commit

Permalink
Fix exception example
Browse files Browse the repository at this point in the history
Fixes dotnet#31951 : Rewrite the exception example so that it's still obvious what can fail, but couldn't be easily anticipated before making the computation.
  • Loading branch information
BillWagner committed Jul 27, 2023
1 parent 1731cef commit 3ca2a4a
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,15 @@ from distributor in distributors
}

//<snippet16>
static string GetValueFromArray(string[] array, int index)
static double ComputeDistance(double x1, double y1, double x2, double y2)
{
try
{
return array[index];
return Math.SquareRoot((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
catch (System.IndexOutOfRangeException ex)
catch (System.ArithmeticException ex)
{
Console.WriteLine("Index is out of range: {0}", index);
Console.WriteLine($"Arithmetic overflow or underflow: {ex}");
throw;
}
}
Expand Down

0 comments on commit 3ca2a4a

Please sign in to comment.