I have one class Message, which takes as parameter a String. If that String is larger than 50 char, i want to create an element of class BigMessage. Now if also that String is larger than 100 char, i want to throw MessageTooBig Exception. Somewhere i have a mistake, because when trying to run it, i have StackOverfrowException at 5th line of BigMessage.
My driver...:
try{
Message msg_1 = new Message("HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello");
}catch(MessageTooBigException e){
System.out.println("Message is too long!");
e.getStackTrace();}
Message...:
public Message(String text) throws MessageTooBigException{
if(text.length()>50){
[COLOR="red"]new BigMessage(text);[/COLOR] //Error here
}
else{
this.text = text;
}
}
public class BigMessage extends Message{
public BigMessage(String text) throws MessageTooBigException{
[COLOR="red"]super(text);[/COLOR] //Error here
if(text.length()>100){
throw new MessageTooBigException("Message too big!");
}
}
}


Sign In
Create Account


Back to top









