重写方法不能抛出异常

hem*_*nth 1 java

在编译以下代码时我遇到了错误

    @Override
public void routeCustomerRequest (int choice) throws UnSupportedCustomerRequestException{
    //throw new UnsupportedOperationException("Not supported yet.");

    switch(choice)
    {
        case '1':
            System.out.println("1. Add a new Customer");
            break;
        default :
            throw  UnSupportedCustomerRequestException("hehehe");
    }
}

  // its constructor class is

public class UnSupportedCustomerRequestException extends Exception {
public UnSupportedCustomerRequestException(String bong){
    System.out.println(bong);
}
Run Code Online (Sandbox Code Playgroud)

}

它的界面是

   /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bankingappication;

/**
 *
 * @author Training
 */
public interface IBankingServices {
    public static String bankerResgistrationCode=null;

    public void enquireCustomer();
    public int presentServiceMenu();
    public void routeCustomerRequest(int choice);

    public boolean acceptDeposit();

    public boolean acceptCheque();
    public boolean processCheque();

    //customer name can be full or partial.
    public boolean provideSummaryStatement(String customerName);

    public boolean addCustomer();
    public boolean removeCustomer();
    public boolean updateCustomer();
}

//please debug the error
Run Code Online (Sandbox Code Playgroud)

Jig*_*shi 6

您不能声明重写方法来抛出更广泛的异常.

在您的情况下,异常总是比例外更广泛