When it is known that some piece of code might throw an error, we make use of try/catch
blocks to ignore such errors and proceed. This is done when the error is not that important but maybe we only want to log it:
try{
int i = 1/0;
} catch( ArithmeticException e){
System.out.println("Encountered an error but would proceed.");
}
x = y;
Such a construct in Java would continue on to execute x = y;
.
Can I make use of match
to do this or any other construct?
I do see a try!
macro, but perhaps it would return in case of an error with the return type of the method as Result
.
I want to use such a construct in a UT to ensure it continues to run even after an error has occurred.