I am trying to capture multiple exceptions like this but I get error '); expected'
. How do I do it using ||
?
try {
//find an element here
}catch( StaleElementReferenceException e || NoSuchElementException e) {
//do something
}
Assuming you're using Java 7, you should be able to use this syntax:
catch (StaleElementReferenceException | NoSuchElementException e)
Note the single |
, as well as the single variable name.
See the "Catching Multiple Exception Types And Rethrowing Exceptions With Improved Type Checking" doc for more details (catchy title, huh?).
If you're not using Java 7, you'll need multiple catch
blocks.
See more on this question at Stackoverflow