How to catch an error?


i have my first appium project running but i have problems catching errors. the test should not fail, it should only find links that don’t work anymore.

What my test is doing is getting a link from a website and put it into a mobile device browser. this link gets forwarded several times and ends at a mobile website or an appstore. the i take the url that is finally reached and check if its a 200, 404 or 505 site, 200 is ok, when its a 404 or 505 error it gets printed on the console and at the end the test fails.

i tried to catch the error by

   try {

                                System.out.println("open mobile chrome");

                                forwardURL = adriver.getCurrentUrl();

                            } catch (InterruptedException e) {

but i still get errors like

Nov 29, 2016 11:10:19 AM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {}-> The target server failed to respond
Nov 29, 2016 11:10:22 AM org.apache.http.impl.execchain.RetryExec execute


Failed tests:
RtasticTest.Test:188 » MalformedURL unknown protocol: data

In catch put Exception not InterruptedException

To expand upon Jitu’s answer. In your initial code, your catch block will only catch exceptions with a type of InterruptedException, while if you only use the generic type of Exception, it will catch all exceptions.

The ability to catch specific types of exceptions can be useful as it allows you to trap and act on a specific exception type (think NoSuchElementException).