/**
 Utility class to dump exceptions in a readable format.
 Useful, for example, when applicaton error dumps are off
 the top of  DOS window.<br><br>

 Use as follows:<br>
 <br>
 try
 {<br>
     new C();<br>
 }<br>
 catch (Throwable e)
 {<br>
     Dumper.dumpTrace(e, 5);<br>
 }<br>


 @version 2002-June-20
 @author Clark S. Lindsey
*/
public class Dumper
{
  static public void dumpTraceElement(
                           StackTraceElement ste)
  {
        System.err.println("filename = " +
            ste.getFileName());
        System.err.println("line number = " +
            ste.getLineNumber());
        System.err.println("class name = " +
            ste.getClassName());
        System.err.println("method name = " +
            ste.getMethodName());
        System.err.println("is native method = " +
            ste.isNativeMethod());
  }


 /**
   Print an array of stack trace elements.
   Use the following to dump, for example, 5 elements

    try
    {
       [method or code block where exception occurs]
    }
     catch (Throwable e)
    {
       Dumper.dumpTrace(e, 5);
    }

  */
  static public void dumpTrace(Throwable e, int numElements)
  {

    // display exception

    System.err.println("Exception: " + e);
    System.err.println();

    // display traceback

    StackTraceElement ste[] = e.getStackTrace();
    int nElementsToDump = ste.length;
    if( numElements > 0) nElementsToDump = numElements;
    for (int i = 0; i < nElementsToDump; i++)
    {
        dumpTraceElement(ste[i]);
        System.err.println();
    }
  }
}
