I have method which calculates angles of triangle when all sides are known:
public static double[] calculateTriangleAngles(double a, double b, double c) {
if (a <= 0 || b <= 0 || c <= 0 || a >= b + c || b >= a + c || c >= a + b) {
throw new TriangleTechnicalException("Incorrect side value");
}
double[] angles = new double[3];
angles[0] = round(Math.toDegrees(Math.acos((pow(b, 2) + pow(c, 2) - pow(a, 2)) / (2 * b * c))), 2);
angles[1] = round(Math.toDegrees(Math.acos((pow(a, 2) + pow(c, 2) - pow(b, 2)) / (2 * a * c))), 2);
angles[2] = round(Math.toDegrees(Math.acos((pow(a, 2) + pow(b, 2) - pow(c, 2)) / (2 * a * b))), 2);
return angles;
}
Calculation algorithm is correct. Question about exception. It must be thrown here.
How can I handle this exception correctly (use throws or try/catch right here or something else?)? Or maybe better throws it (but this method can looks not correctly, surrounded try/catch in tests)?
Can you help me with this question?
Aucun commentaire:
Enregistrer un commentaire