In Exceptions II - Challenge 2 should doesSomethingDangerous already have a throws Exception attached to it? Or is this up to the individual to recognize?
Current written structure:
/*The following program will not compile. Make it compile by
propagating the checked exception thrown
by the doesSomethingDangerous method.
*/
int doesSomethingDangerous(int value) {
if (value == 1) {
throw new Exception("1 does not work");
}
return 3 * value + 2;
}
int compute(int start) {
return square(doesSomethingDangerous(start));
}
int square(int x) {
return x * x;
}
void main() {
int x = Integer.parseInt(IO.readln("Give a starting number: "));
IO.println(compute(x));
}
Potential line fix.
int doesSomethingDangerous(int value) throws Exception {
if (value == 1) {
throw new Exception("1 does not work");
}
return 3 * value + 2;
}
int compute(int start) {
return square(doesSomethingDangerous(start));
}
int square(int x) {
return x * x;
}
void main() {
int x = Integer.parseInt(IO.readln("Give a starting number: "));
IO.println(compute(x));
}
In Exceptions II - Challenge 2 should
doesSomethingDangerousalready have a throws Exception attached to it? Or is this up to the individual to recognize?Current written structure:
Potential line fix.