Use the exception class MessageTooLongException in a program
Solution
Import java .util.scanner;
Import java.util.*;
Import java .io.*;
Class meaasgelong extends message too long exception
{
Public static void main (string [] args)
{
Try
{
Char ch;
Do
{
Scanner keyboard=new scanner (system. in);
System.out.println (“enter the text :”);
String hr=keyboard.nextline ();
Int count=hr.length ();
If (count>=20)
Throw new message too long exception (0;
Else
{
System.out.println (‘you entered”+count+ “characteristics which is an acceptable length.”);
}
System .out.println (“do you want to continue? (Y/n”);
Buffered reader br=new new buffered reader (new input stream reader (system. in));
String s= br.readline ();
Ch=s.charat (0);
} while ((ch==’y’)// (ch==’y’));
} catch (messagetoolongexception ex)
{
System.out.println (ex.getmessage ());
}
Catch (ioexception ex)
{
System.out.println (ec.getmessage ());
}
}
}
Class message too long exception extends exception
{
Public message too long exception ()
{
Super (“message too long exception”);
}
Public message too long exception (string message)
{
Super (message);
}
}

