You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HelloWorld.java 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package hello;
  2. import java.io.BufferedInputStream;
  3. import java.io.BufferedReader;
  4. import java.io.ByteArrayInputStream;
  5. import java.io.ByteArrayOutputStream;
  6. import java.io.IOException;
  7. import java.io.InputStreamReader;
  8. import java.io.PrintStream;
  9. public class HelloWorld {
  10. public void println () {
  11. System.out.println("Hello World!");
  12. }
  13. private void testStackTrace () throws IOException {
  14. try {
  15. println();
  16. }
  17. catch (Exception ex) {
  18. printRelevantStackEntries(ex,getClass().getName());
  19. }
  20. }
  21. private static void printRelevantStackEntries (Exception ex, String className) throws IOException {
  22. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  23. PrintStream ps = new PrintStream(baos);
  24. ex.printStackTrace(ps);
  25. ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
  26. BufferedReader br = new BufferedReader(new InputStreamReader(bais));
  27. String entry;
  28. while ((entry = br.readLine()) != null) {
  29. if (entry.indexOf(className) != -1) {
  30. System.err.println(entry);
  31. }
  32. }
  33. }
  34. public static void main(String[] args) throws Exception {
  35. new HelloWorld().testStackTrace();
  36. }
  37. }