I am trying to implement my own exception class. According to the condition, it must display an error message by default (“Device Unavailable”) and have a “device” field with a getter that stores an invalid device object that caused an exception.
I do this:public class DeviceValidationException extends RuntimeException { public void start() throws IllegalStateException{ throw new IllegalStateException ("Device is not valid for operation"); } protected int device; public int getDevice() throws IllegalStateException{ try { return device; } catch (IllegalStateException e){ System.out.println("Device is not valid for operation"); throw e; } } But there is a serious suspicion that this is wrong and my het-method does not store at all what is needed. Also, do I need a setter in a pair?
Next, you need to implement a constructor with 2 string arguments, which will be passed the name of the operation for which the device turned out to be invalid (as I understand it, this will be the getDevice method, but I don’t understand how to do it) and the device Device object, which led to an exception. In this case, the constructor must call the parent constructor with a string argument, but not transmit the incoming string, but collect it from the default message and, if the incoming one is not null, add it through the space. The device argument specifies the value of the device field. And then the problem arose on the constructor declaration ( DeviceValidationException (String operation, Device device){ super(operation, device); } The compiler swears on device.