0

expected to be thrown but nothing was thrown

I make a junit test for a programm and the error is that it was expection an thrown error but nothing was thrown. What could be the problem? public static double calcArea(double a, double b, double c) { checkTriangle(a, b, c); double s = (a + b + c)/2; return Math.sqrt(s * (s - a) * (s - b) * (s - c)); } private static void checkTriangle(double a, double b, double c) { // checkIfNumbersArePositive(a, b, c); //checkIfNumbersAreTooBig(a,b,c); checkRatio(a, b, c); } private static void checkRatio(double a, double b, double c) { try { if (a + b <= c) { throw new NotATriangleException("Wont form a Triangle"); } } catch(Exception e){ e.toString(); } }

2nd Mar 2021, 2:12 PM
Manfred h
3 Answers
0
Maybe a+b is not <= c? Paste your whole code in a playground and link it here Btw what is "NotATriangleException"? I guess it's your own type, so maybe you catch wrong type?
2nd Mar 2021, 2:22 PM
Michal Doruch
2nd Mar 2021, 2:29 PM
Manfred h
0
yes NotATriangleException is my own type
2nd Mar 2021, 3:12 PM
Manfred h