Jump to content

Create an Exception

- - - - -

  • Please log in to reply
1 reply to this topic

#1
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
Hello,

Never created an exception class before, so im finding it lil difficult. I have a Message class that takes a String text. Asked to me to create MessageTooBigException when text message is longer than 50 char.
So until now i have:

My Message class


public Message(String message) throws MessageTooBigException{

   this.message = message;

}

My driver class


try{

	Message msg_1 = new Message("Hello");

	Message msg_2 = new Message("How are you today?");

	Message msg_3 = new Message("Im fine. How are you?");

	

}catch(MessageTooBigException m){

			

}


My exception class


public class MessageTooBigException extends Exception {


	public MessageTooBigException(String alert){

		

	}

	

	

}


As you can see my exception class still empty. How i should move on now?
thank you

"Programming is like sex. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#2
nicckk

nicckk

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 629 posts


public class MessageTooBigException extends Exception {


	public MessageTooBigException(String alert){

		super(alert);

	}






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users