fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. try { test_1(null); }
  10. catch (NullPointerException e) { System.out.println("NullPointerException"); }
  11.  
  12. try { test_2(null); }
  13. catch (UnsupportedArgumentException e) { System.out.println(e.getMessage()); }
  14.  
  15. try { test_1(Color.Green); }
  16. catch (UnsupportedArgumentException e) { System.out.println(e.getMessage()); }
  17. }
  18.  
  19. public static String test_1 (Color color) throws Exception
  20. {
  21. String out = "";
  22.  
  23. switch (color) // NullPointerException expected
  24. {
  25. case Red:
  26. out = Color.Red.getName();
  27. break;
  28. case Blue:
  29. out = Color.Red.getName();
  30. break;
  31. default:
  32. throw new UnsupportedArgumentException ("unsupported color: " + color.getName());
  33. }
  34.  
  35. return out;
  36. }
  37.  
  38. public static String test_2 (Color color) throws Exception
  39. {
  40. if (color == null) throw new UnsupportedArgumentException ("unsupported color: NULL");
  41. return test_1(color);
  42. }
  43. }
  44.  
  45. enum Color
  46. {
  47. Red("Red"), Blue("Blue"), Green("Green");
  48. private final String name;
  49. private Color(String n) { name = n; }
  50. public String getName() { return name; }
  51. }
  52.  
  53.  
  54. class UnsupportedArgumentException extends Exception
  55. {
  56. private String message = null;
  57.  
  58. public UnsupportedArgumentException() { super(); }
  59.  
  60. public UnsupportedArgumentException (String message)
  61. {
  62. super(message);
  63. this.message = message;
  64. }
  65.  
  66. public UnsupportedArgumentException (Throwable cause) { super(cause); }
  67.  
  68. @Override public String toString() { return message; }
  69.  
  70. @Override public String getMessage() { return message; }
  71. }
  72.  
Success #stdin #stdout 0.12s 320576KB
stdin
Standard input is empty
stdout
NullPointerException
unsupported color: NULL
unsupported color: Green