fork download
  1. import java.io.InterruptedIOException;
  2. import java.nio.file.FileSystemException;
  3.  
  4. class Test {
  5. public void foo() throws InterruptedIOException {
  6. try {
  7. // compiler knows the exact class of the exception, so we do not have
  8. // to define one in the `catch` block explicitly
  9. } catch (Exception ex) {
  10. // do something with the exception (logging?)
  11. throw ex;
  12. }
  13. }
  14.  
  15. public void bar(int i) throws InterruptedIOException {
  16. try {
  17. if (i < 0) {
  18. } else {
  19. throw new FileSystemException("test");
  20. }
  21. } catch (Exception ex) {
  22. // do something with the exception (logging?)
  23. throw ex; // compile-time error
  24. }
  25. }
  26. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:25: error: unreported exception FileSystemException; must be caught or declared to be thrown
            throw ex; // compile-time error
            ^
1 error
stdout
Standard output is empty