ERROR - Exception is not compatible with throws clause in xyz.method

Error

Exception is not compatible with throws clause in xyz.method()

Error Type 

Compile Time

Sample Code 

class BuggyBread1{
public String method(){
System.out.println("String Method 1");
return null;
}
}

class BuggyBread2{
public String method() throws Exception{
System.out.println("String Method 2");
return null;
}
}

Cause

Exception thrown by the method in the derived class should be compatible with the overridden method.

Resolution

Either remove the thrown exception in the derived class method 


class BuggyBread1{
public String method(){
System.out.println("String Method 1");
return null;
}
}

class BuggyBread2{
public String method(){
System.out.println("String Method 2");
return null;
}
}

or throw a compatible exception in the overriden method 


class BuggyBread1{
public String method() throw Exception{
System.out.println("String Method 1");
return null;
}
}

class BuggyBread2{
public String method() throws Exception{
System.out.println("String Method 2");
return null;
}
}