我不知道爲什麼我得到這個錯誤,並有一種感覺我錯過了一些明顯的東西在這裏。它發生在行上:Verify.Validate(number);錯誤:Program5.java:23:錯誤:未報告的異常異常;必須被捕獲或宣佈被拋出。任何建議,將不勝感激。異常處理編譯錯誤:異常;必須被捕獲或被宣佈爲拋出
克里斯
import java.util.Scanner;
public class Program5
{
public static void main(String[] args)
{
// The driver class should instantiate a Verify object with a range of 10 to 100.
Verify Verify = new Verify(10, 100);
//Prompt the user to input a number within the specified range.
System.out.print("Input a number between 10-100: ");
// Use a Scanner to read the user input as an int.
Scanner input = new Scanner(System.in);
int number = input.nextInt();
// Use Try/Catch to test number
try
{
Verify.Validate(number);
System.out.println("Number entered: " + number);
}
catch (NumberNegativeException ex)
{
System.out.println(ex.getMessage());
}
catch (NumberLowException ex)
{
System.out.println(ex.getMessage());
}
catch (NumberHighException ex)
{
System.out.println(ex.getMessage());
}
}
}
解決方法是在錯誤消息 – Reimeus 2014-10-17 16:49:53
是,無論是「catch(Exception)」還是讓主方法拋出異常 – spiderman 2014-10-17 16:51:48
這必須是大約1000倍以上的愚蠢。 – 2014-10-17 17:02:48