Menu

#1 choose the most appropriate method during exception handling

v1.0_(example)
open
nobody
None
5
2009-09-08
2009-09-08
No

Hi,
This is MyHandler class code.

public class MyHandler implements Handler {
@Override
public Populator getPopulator() {
return null;
}

public Throwable handle(ArrayIndexOutOfBoundsException arg0, int c) {
System.out.println("Array Index out of bounds exception");
return null;
}
@Override
public Throwable handle(Throwable arg0, Object... arg1) {
System.out.println("Null Pointer Exception");
return null;
}
}

This is my Test program code.

public class Test {
@ExceptionHandler(handler=MyHandler.class)
public void methodA() {
int c[] = {1,2};
try {
System.out.println(c[5]);
}catch (Exception e) {
HandlerUtil.handle(e,c);
}
}

public static void main(String...args){
new Test().methodA();
}
}

When I execute my program this is output.
[2009-09-08 12:01:05,328] [INFO ] [org.codecompany.jeha.core.HandlerContextPopulator] - No exception mapper specified for class 'com.java.Test'. Using default
[2009-09-08 12:01:05,468] [INFO ] [org.codecompany.jeha.core.HandlerContext] - Using handler 'com.java.MyHandler' for method 'com.java.Test.methodA'
Null Pointer Exception

In this Test program methodA() is throwing ArrayIndexOutOfBoundsException. In the MyHandler class is invoking the handle method
which takes Throwable object and its not calling the specific method which takes ArrayIndexOutOfBoundsException object.

Please let me know any mistake I am doing or configuration is missing.

Thanks in advance
Dhananjay

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.