1. protected final HashSet<TestObjectExceptionHandler> checkedInExceptionHandlers = new HashSet<TestObjectExceptionHandler>();
  2. //this will be invoked when some exception is caught out
  3. private ITestObjectExceptionHandler exceptionHandler = (ITestObjectExceptionHandler) Proxy.newProxyInstance(
  4. IExtendedWebDriverEventListener.class.getClassLoader(),
  5. new Class[] {ITestObjectExceptionHandler.class },
  6. new InvocationHandler()
  7. {
  8. public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
  9. {
  10. //it needs to know exception
  11. Throwable t = (Throwable) args[4];
  12. for (TestObjectExceptionHandler handler : checkedInExceptionHandlers)
  13. {
  14. //it looks for the suitable handler
  15. if (handler.throwableList.contains(t.getClass()))
  16. {
  17. try
  18. {
  19. return method.invoke(handler, args);
  20. }
  21. catch (Exception e) {
  22. continue; //it wasn't the suitable handler
  23. }
  24. }
  25. }
  26. //if there are no suitable handlers
  27. throw t;
  28. }
  29. }
  30. );
Comments powered by Disqus