​​Solutions to Prevent IndexOutOfRangeException (part 3)



Solution 2: Use the try catch blocks to catch the IndexOutOfRangeException.



In the above example, the entire code wrapped inside the try block may throw errors. The catch block has the Exception filter that can catch any exceptions. So, when the arr[5] statement inside the try block throws an exception, the catch block captures the IndexOutOfRange exception and displays an error message, and continues the execution.



💬 If you appreciate this channel and want it to grow, why not support it: https://www.patreon.com/csharp1001notes