Exception-getMessage method returns the index? | Selenium Forum
M
Posted on 12/06/2016
When array is out of bound and e.getMessage() method is used to print the same exception, this method returns the Index of the array but not the message.
Is this correct?

public class Test {
public static void main(String[] args) {
int o[] = new int[2];
try{
o[3]=23;
o[1]=33;
}catch(Exception e){
System.out.println(e.getMessage());}
}
}

M
Replied on 14/06/2016

there are only 2 arrays

[code:2m819rcz]int o[] = new int[2];
try{
o[3]=23;
o[1]=33;
}catch(Exception e){
System.out.println(e.getMessage());}
}
[/code:2m819rcz]

o[3] you can only do o[0] o[1]


M
Replied on 14/06/2016

I understand that o[3] array can have o[0], o[1], o[2] elements in it. But my question is when we use e.getMessage() method, should it return the exception name? (in this case it would be ArrayOutOfBound) or it should return the index of array? (which is exceeded and in this case it is 3). Because, right now when I use this method on this example, it returns the index i.e. 3.

Can you please clarify?


M
Replied on 15/06/2016

i'm not able to understand what you're asking?


M
Replied on 15/06/2016

What should be the output of the following code?
public class Test {
public static void main(String[] args) {
int o[] = new int[2];
try{
o[3]=23;
o[1]=33;
}catch(Exception e){
System.out.println(e.getMessage());}
}
}

Should it be: "3"? or Should it be "ArrayOutOfBound Exception"?
Basically, my question is: what will "e.getMessage()" return in this program?


M
Replied on 16/06/2016

it should be 3.