Writing code for an exception should include the following components:

A simple program that requires exception handling follows:

import java.io.*;
public class HelloName{
public static void main(String args[] ) {
final int LENGTH = 255;
byte buffer[] = new byte [LENGTH]
System.out.print(“Enter your name:   “);
try{
    System.in.read(buffer, 0, LENGTH);
     }
catch (Exception e)   {  }
String name = new String(buffer);
System.out.println(“Hello, “ + name.trim() + “!”)
      }
}