Recover from division by zero
try holds code that might fail; a matching catch runs instead if it does, and later code still runs.
Your task
Wrap calls to a calculator in try/catch so dividing by zero is caught and later code still runs.
class RatioCalculator {
public Decimal divide(Decimal numerator, Decimal denominator) {
return (numerator / denominator).setScale(2);
}
}
RatioCalculator calculator = new RatioCalculator();Requirements
catch (MathExceptionshould be presentgetTypeName()should be presentNormal: 4.00should be built from runtime valuesNormal: 4.00should be printedDivide by zero: System.MathExceptionshould be printedAfter catch: 3.00should be printed- The three lines should be printed in order