Write a program to print a Stact Trace Message.

public class PrintStack
{
           public static void main (String args[])
              {
               String str = "Exception" ;
               int len=0;
           try
              {
             StringBuffer sbuf = new StringBuffer(str);
            len = str.length() ;
           for(int ct=len;ct>=0;ct--)
            {
          System.out.print(sbuf.charAt(ct));
           }
       }
       catch(Exception e)
      {
      e.printStackTrace();
       }
     }
   }



OUTPUT OF THE PROGRAM:-


java.lang.StringIndexOutOfBoundsException: String index out of range: 9
at java.lang.StringBuffer.charAt(Unknown Source)
at PrintStack.main(PrintStack.java:13)

No comments:

Post a Comment