How to prevent IndexOutOfRangeException exception
Loading
How to prevent IndexOutOfRangeException exception
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pushpendra ShuklaPosted Jul 13, 2022, 12:48 PM
What is the Index Out of Range Exception?
If we initialize the array size and print the value greater than the array size. For example, we initialize the array size 5 and we print the values of 6 index that time array shows Index Out of Range Exception.
This is the code for preventing Index Out of Range Exceptions.
Output
How to handle this exception
This is the solution to handle the Index Out of Range Exception.
output
PhamNgoc KhiemPosted Jul 13, 2022, 7:28 AM
This is the error was occurred by your index query exceed the total index array. You can prevent it by this way
Muhammad Imran AnsariPosted Jul 5, 2022, 8:13 PM
Salman BegPosted Jul 5, 2022, 6:27 PM
Jaydeep PatilPosted Jul 3, 2022, 5:50 AM
Take care of your index and size of the collection while iterating and also handle exception properly.
Rajanikant HawaldarPosted Jul 2, 2022, 6:07 PM
Joginder BangerPosted Jul 2, 2022, 2:51 PM