Skip to content

Commit

Permalink
Custom exceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMerfy committed Feb 17, 2018
1 parent 5752a1c commit ec9b31c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Grapher/src/graph/LineGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ private void initialize(double width, double height){
this.onRenderCompleted = new SimpleBooleanProperty();
}

public void render(Render value) throws Exception {
public void render(Render value) throws RenderException {
//Check if graph is valid
if (points.size() < 3)
throw new Exception("Cannot render graph with less the 3 points in it.");
throw new RenderException("Insufficient points in graph.", new Throwable("Graph was tried to be rendered using "+points.size()+" points."));

//Sort points based on x-axis
if(isManualEntry){
Expand Down Expand Up @@ -257,7 +257,7 @@ public BooleanProperty onRenderCompletedProperty() {
///////////////////////////////////////////////////////////////////////////
// POINT ADDERS
///////////////////////////////////////////////////////////////////////////
public void addValue(double value){
public void addValue(double value) throws RenderException {
addPointLocal(new Point2D(currentX, value));
currentX+= interval;
}
Expand All @@ -267,16 +267,16 @@ public void addValue(double value){
* @param x The x cartesian coordinates of the point.
* @param y The y cartesian coordinates of the point.
*/
public void addPoint(double x, double y){
public void addPoint(double x, double y) throws RenderException {
addPointLocal(new Point2D(x,y));
isManualEntry = true;
}

private void addPointLocal(Point2D point){
private void addPointLocal(Point2D point) throws RenderException {
if(point.getX() == Double.NaN)
throw new RuntimeException("X value must be a number.");
throw new RenderException("Invalid value.", new Throwable("X value must be a number."));
if(point.getY() == Double.NaN)
throw new RuntimeException("Y value must be a number.");
throw new RenderException("Invalid value.", new Throwable("Y value must be a number."));
points.add(point);
}

Expand Down
16 changes: 16 additions & 0 deletions Grapher/src/graph/RenderException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package graph;

/**
* Custom exception handling for the exceptions throwed by the graph.
*/
public class RenderException extends Exception {

public RenderException(String message) {
super(message);
}

public RenderException(String message, Throwable cause) {
super(message, cause);
}

}

0 comments on commit ec9b31c

Please sign in to comment.