Skip to content

Commit 6222357

Browse files
committed
Create custom exception.
1 parent d6c7a3b commit 6222357

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/main/java/main/elements/PolygonElement.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ public PolygonElement(List<Point2D> pointList, Color backgroundColor, Color bord
5959
{
6060
if (pointList.size() < 3)
6161
{
62-
// TODO Probably need to create Exceptions?
63-
throw new ArrayIndexOutOfBoundsException("Too small pointList");
62+
throw new CustomException("Point list is too small. It must contains at least 3 points!");
6463
}
6564

6665
this.pointList = pointList;
@@ -185,6 +184,23 @@ public void setPosition(Point2D position)
185184
}
186185

187186

187+
// ---------------------------------------------------------------------
188+
// Section: Private Classes
189+
// ---------------------------------------------------------------------
190+
191+
192+
/**
193+
* This custom Exception throw message when Polygon point list is too small.
194+
*/
195+
private class CustomException extends RuntimeException
196+
{
197+
public CustomException(String message)
198+
{
199+
super(message, new Throwable(message), true, true);
200+
}
201+
}
202+
203+
188204
// ---------------------------------------------------------------------
189205
// Section: Variables
190206
// ---------------------------------------------------------------------

0 commit comments

Comments
 (0)