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. class IntFrom0to1 {
  8. public class InvalidValueException extends Exception {
  9. public InvalidValueException(String message) {
  10. super(message);
  11. }
  12. }
  13.  
  14. int value;
  15. public IntFrom0to1(int value) throws InvalidValueException {
  16. if(value > 1)
  17. throw new InvalidValueException("Value is out of range");
  18. this.value = value;
  19. }
  20. }
  21.  
  22. /* Name of the class has to be "Main" only if the class is public. */
  23. class Ideone
  24. {
  25. public static void main (String[] args) throws java.lang.Exception
  26. {
  27. try {
  28. IntFrom0to1 a = new IntFrom0to1(0);
  29. IntFrom0to1 b = new IntFrom0to1(-1);
  30. }
  31. catch(Exception e) {
  32. e.printStackTrace(System.out);
  33. }
  34. }
  35. }
  36.  
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
Standard output is empty