I'm trying to override a method, with throwing an exception:
class A {
public doSomething(){
// some of logic
}
}
class B extends A {
public doSomething() throws MyCustomizedException {
try {
// some of logic
} catch(ExceptionX ex ) {
throw new MyCustomizedException(" Some info ", ex);
}
}
}
But I get this compile time error :
Exception MyCustomizedException is not compatible with throws clause in A
The two constraints are :
- Using the same name of the function and the same arguments if they exist: doSomething()
- Throwing my customized exception
How can I get rid of the exception?
Thank you a lot.