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 != 0 && 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)
  26. {
  27.  
  28. IntFrom0to1 a = new IntFrom0to1(0);
  29. IntFrom0to1 b = new IntFrom0to1(2);
  30.  
  31.  
  32. }
  33. }
  34.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:28: error: unreported exception IntFrom0to1.InvalidValueException; must be caught or declared to be thrown
			IntFrom0to1 a = new IntFrom0to1(0);
			                ^
Main.java:29: error: unreported exception IntFrom0to1.InvalidValueException; must be caught or declared to be thrown
			IntFrom0to1 b = new IntFrom0to1(2);
			                ^
2 errors
stdout
Standard output is empty