I have a class, Line
, which takes two points, given as vectors, as a parameter and models the infinite line passing between them. A second class, BoundedLine
, takes two points and models the finite line connecting them.
An exception is thrown by Line
if the two points are the same, meaning that the call to the super constructor in BoundedLine
needs to be wrapped in a try catch block. Unfortunately it seems that the parameters are not available inside the try block; how would I access them?
// Constructor in Line
public Line (Vector start, Vector end) throws Exception {
if (start.equals (end)) {
throw new Exception ( "Points are the same" );
}
else {
this.start = start;
this.end = end;
modelLine (start, end);
}
}
// Constructor in BoundedLine
public BoundedLine (Vector start, Vector end) throws Exception {
try {
super (start, end);
}
catch (Exception e) {
throw e;
}
applyBoundaries (start, end);
}
I'm getting a compile time error of: "constructor Line in class Line cannot be applied to given types; required: Vector,Vector; found: no arguments; reason: actual and formal argument lists differ in length".
If I remove the exceptions and the try/catch block, then the code works fine.