

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to capture out of array index out of bounds exception in Java?
When you try to access an element of an array at an index which is out of range, an ArrayIndexOutOfBoundsException exception is raised.
Example
public class ArrayIndexOutOfBounds { public static void main(String args[]) { try { int[] a = new int[]{1,2,3,4,5}; int x = 6; a[10] = x; } catch(ArrayIndexOutOfBoundsException ex) { System.out.println("Array size is restricted to 5 elements only"); } } }
Output
Array size is restricted to 5 elements only
- Related Questions & Answers
- How to handle Java Array Index Out of Bounds Exception?
- How to capture index out of range exception in C#?
- How to capture out of memory exception in C#?
- What is out of bounds index in an array - C language?
- Accessing array out of bounds in C/C++
- Out of memory exception in Java:
- Why accessing an array out of bounds does not give any error in C++?
- How to capture divide by zero exception in Java?
- How to capture file not found exception in Java?
- Set storage-indexed locations to corresponding values and wrap out-of-bounds indices in Numpy
- How to filter out common array in array of arrays in JavaScript
- Get closest number out of array JavaScript
- Why substring slicing index out of range works in Python?
- Breaking out of nested loop in java
- Set storage-indexed locations to corresponding values and clip out-of-bounds indices to range in Numpy
Advertisements