fork download
  1. import javax.naming.NamingException;
  2. import java.io.FileNotFoundException;
  3. import java.io.IOException;
  4. import java.nio.channels.ClosedChannelException;
  5. import java.rmi.activation.ActivationException;
  6. import java.util.Arrays;
  7.  
  8. public class Main{
  9.  
  10. public static void main(String[] args) throws NamingException {
  11. try {
  12.  
  13.  
  14. try(
  15. DummyIO dummy = new DummyIO(false,true); //-- try with different true, false values
  16. ){
  17. throw new ActivationException();
  18. System.out.println("Inner: Caught: " + e1);
  19. System.out.println("Inner: suppressed: " + Arrays.toString(e1.getSuppressed()));
  20. throw new SecurityException(e1);
  21. }finally {
  22. throw new NamingException();
  23. }
  24.  
  25.  
  26. }catch (NamingException e2){
  27. System.out.println("Outer: Caught: " + e2);
  28. System.out.println("Outer: suppressed: " + Arrays.toString(e2.getSuppressed()));
  29. }
  30.  
  31. }
  32.  
  33.  
  34. private static class DummyIO implements AutoCloseable{
  35. private boolean throwInClose;
  36.  
  37. private DummyIO(boolean throwInConstructor, boolean throwInClose) throws FileNotFoundException {
  38. if(throwInConstructor){
  39. throw new FileNotFoundException();
  40. }
  41. this.throwInClose = throwInClose;
  42. }
  43.  
  44. @Override
  45. public void close() throws Exception {
  46. if(throwInClose){
  47. throw new ClosedChannelException();
  48. }
  49. }
  50. }
  51.  
  52. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
Inner: Caught: java.rmi.activation.ActivationException
Inner: suppressed: [java.nio.channels.ClosedChannelException]
Outer: Caught: javax.naming.NamingException
Outer: suppressed: []