fork(1) 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) // Surprised I don't need throws Exception.
  11. {
  12. try {
  13. } catch (Exception e) {
  14. throw e;
  15. }
  16. }
  17.  
  18. static void stillCompilesWithThrownUncheckedException() {
  19. try {
  20. throw new NullPointerException();
  21. } catch (Exception e) {
  22. throw e;
  23. }
  24. }
  25.  
  26. static void doesNotCompileWithThrownCheckedException() {
  27. // Doesn't compile with checked exception.
  28. try {
  29. throw new Exception();
  30. } catch (Exception e) {
  31. throw e;
  32. }
  33. }
  34. }
Compilation error #stdin compilation error #stdout 0.11s 320576KB
stdin
Standard input is empty
compilation info
Main.java:31: error: unreported exception Exception; must be caught or declared to be thrown
			throw e;
			^
1 error
stdout
Standard output is empty