Hi my code is generating an arrayoutofbound exception which is caught in the code but code terminates abruptly.I want the code to continue. Should an arrayoutofboundexception be caught by Exception or am i doing something wrong, please help catching the error .Exception is expected.Below is the code:-
try{
CsgLogin=Ldap.getdomain(requesterLoginId);//This returns domain\usernmae
LoginIDArray = CsgLogin.split("\\\\");
requesterLoginId = LoginIDArray[1]; //Exception generated here
} catch(Exception e) {
System.out.println("Error in the GLDAP lookup or error in Domain Mapping");
e.printStackTrace();
}
output:
java.lang.ArrayIndexOutOfBoundsException: 1
at com.cs.ws.LdapConnect.getdomain(LdapConnect.java:131)
at com.cs.ws.AgentConnector.startOfBreakGlass(AgentConnector.java:476)
at com.cs.ws.AgentConnector.runBreakGlassProcess(AgentConnector.java:208)
at com.cs.ws.MyAccessTimer.main(MyAccessTimer.java:93)
Error in the GLDAP lookup or error in Domain Mapping
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1768)
at com.cs.ws.DomainMap.getDomain(DomainMap.java:21)
at com.cs.ws.AgentConnector.startOfBreakGlass(AgentConnector.java:477)
at com.cs.ws.AgentConnector.runBreakGlassProcess(AgentConnector.java:208)
at com.cs.ws.MyAccessTimer.main(MyAccessTimer.java:93)
The
ArrayIndexOutOfBoundsExceptionis being caught: you can tell by the fact that your messageError in the GLDAP lookup or error in Domain Mappingis printed. The first block that you are seeing is just whatprintStackTrace()produces.The two aren’t in order because one is printing to the standard output stream and the other is printing to the standard error stream.
The exception that is uncaught is the
StringIndexOutOfBoundsExceptionthat is printed under your message.