I was trying an example about try catch but it isn't working as I wanted. This is the code :
public static void main(String[] args)
{
//This array's size is 5 and it has 4 Strings in it.
String[] array = new String[5];
array[0] = "Hello";
array[1] = "World";
array[2] = "try catch";
array[4] = "error";
try
{
for(int i = 0 ; i<array.length ; i++)
System.out.println("This array has: "+array[i]);
} catch (NullPointerException e)
{
System.out.println("Null!!!");
}
}
output is like that :
This array has: Hello
This array has: World
This array has: try catch
This array has: null
This array has: error
It supposed to enter catch block but it didn't. Any ideas?