Using Super in a Derived Class Constructor When Base Class Requires Exceptions to be Caught-Collection of common programming errors
I’m trying to derive a class B to a new class C in Java. The base class constructor requires that unreported exceptions must be thrown or caught. But if I try to put super(..) inside a try/catch then I’m told that the call to super must be the first statement in the constructor. Does anyone know a way around this?
public class C extends B
{
//Following attempt at a constructor generates the error "Undeclared exception E; must be caught or declared
//to be thrown
public C(String s)
{
super(s);
}
//But the below also fails because "Call to super must be the first statement in constructor"
public C(String s)
{
try
{
super(s);
}
catch( Exception e)
{
}
}
}
Many thanks, Chris