0
Wouldn't it be sufficient just to surround the Console.WriteLine statement with the try-block? Why the array declaration as well?
3 Answers
+ 2
Actually you don't need to surround the array declaration with the try-catch block. There's anything wrong with that line, it's just a normal array. What causes the problem is the Console.WriteLine() call, so it's the only one you need to surround, but it's a normal practice tu surround all of the related code in the same try-catch block. If you continue learning you will find the try-with-resources, wich is a nice example of why to surround more code. You can try to surround the method call only in the code playground, you will see it still works.
+ 1
Hello! The reason we surrounded the array call was because there is nothing in the array at the index of 8. If we didn't handle it, it would raise an error that would end the program. I hope this cleared this up for you.
0
Where is the code?