Creating exception classes
We will create two exception classes because we need to throw exception types that aren't represented by any of the types included in the Java 9 platform. Specifically, we will create two subclasses of the java.lang.Exception
class.
The following lines declare the InsufficientMembersException
class that inherits from Exception
. We will throw this exception when a party has an insufficient number of members to perform an operation that requires more members to be executed. The class defines an immutable numberOfMembers
private field of the int
type that is initialized with the value received in the constructor. In addition, the class declares a getNumberOfMembers
method that returns the value for this field. The code file for the sample is included in the java_9_oop_chapter_10_01
folder, in the example10_01.java
file.
public class InsufficientMembersException extends Exception { private final int numberOfMembers; public InsufficientMembersException(int numberOfMembers...