fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. new Printer("Message: ");
  13.  
  14. try {
  15. throw new Exception();
  16. }
  17. catch(Exception e) {
  18. //This works
  19. Printer.print(e.toString());
  20.  
  21. //This generates a cannot find symbol error when compiling
  22. Printer.printError(e);
  23. // ^ here
  24. }
  25. }
  26. }
  27.  
  28. class Printer {
  29. private static String errorTitle;
  30. private static String regularTitle;
  31.  
  32. Printer(String regularTitle_) {
  33. errorTitle = "Some error: ";
  34. regularTitle = regularTitle_;
  35. }
  36.  
  37. public static void printError(Exception e) {
  38. System.out.println(errorTitle + e.getMessage());
  39. }
  40.  
  41. public static void print(String message) {
  42. System.out.println(regularTitle + message);
  43. }
  44. }
Success #stdin #stdout 0.11s 320576KB
stdin
Standard input is empty
stdout
Message: java.lang.Exception
Some error: null