In a file called Team.java I have the following (I only show part of the code):
public class Team{
private static final String MSG_ERR_ENERGY_RANGE_VALUE = "[ERROR] Team's energy cannot negative either greater than 100!!";
private static final String MSG_ERR_HEIGHT_VALUE = "[ERROR]: Team's height cannot negative either 0!!";
..........
public void setEnergy(int energy) throws Exception {
if(energy<0 || energy>100) throw new Exception(MSG_ERR_ENERGY_RANGE_VALUE);
..........
public void setHeight(double height) throws Exception{
if(height<=0) {
throw new Exception(MSG_ERR_HEIGHT_VALUE);
..........
I have to create a class called TeamException which inherits from Exception. The code is the following:
public class TeamException extends Exception{
public TeamException() {
super();
}
public TeamException(String msg) {
super(msg);
}
}
What I have to do is transfer the String type attributes that contain the exception messages from the Team.java file to the TeamException.java file. How can I do this?
Create a message attribute on the class
TeamException
and override the methodgetMessage()
, the code should look like this: