✏️ Explanatory Question
int X = -5; // example value
try {
if (X < 0) {
throw new Exception("ERROR: Negative value in X coordinate");
}
System.out.println("X is valid: " + X);
}
catch (Exception e) {
System.out.println(e.getMessage());
}
Output:
ERROR: Negative value in X coordinate