Practice · 1 of 2
Exception cost, measured
CHALLENGE
Difficulty: advanced+25 XP
Implement static long ThrowCatchCost(int iterations): capture Stopwatch ticks for iterations throw+catch cycles of a pre-created exception instance (throw ex; inside try, catch { }) and return the elapsed milliseconds. Then implement static long ErrorCodeCost(int iterations) doing the same work but returning -1 instead of throwing (checked, same loop shape). Implement static int Divide(int a, int b) that throws DivideByZeroException on b==0 — used by the test once to verify the exception path works.
Press Submit to check your solution.
Back to lesson: Practice: CLR internals drills