< prev index next >

src/java.base/windows/classes/sun/nio/fs/WindowsException.java

Print this page




  52 
  53     int lastError() {
  54         return lastError;
  55     }
  56 
  57     String errorString() {
  58         if (msg == null) {
  59             msg = WindowsNativeDispatcher.FormatMessage(lastError);
  60             if (msg == null) {
  61                 msg = "Unknown error: 0x" + Integer.toHexString(lastError);
  62             }
  63         }
  64         return msg;
  65     }
  66 
  67     @Override
  68     public String getMessage() {
  69         return errorString();
  70     }
  71 







  72     private IOException translateToIOException(String file, String other) {
  73         // not created with last error
  74         if (lastError() == 0)
  75             return new IOException(errorString());
  76 
  77         // handle specific cases
  78         if (lastError() == ERROR_FILE_NOT_FOUND || lastError() == ERROR_PATH_NOT_FOUND)
  79             return new NoSuchFileException(file, other, null);
  80         if (lastError() == ERROR_FILE_EXISTS || lastError() == ERROR_ALREADY_EXISTS)
  81             return new FileAlreadyExistsException(file, other, null);
  82         if (lastError() == ERROR_ACCESS_DENIED)
  83             return new AccessDeniedException(file, other, null);
  84 
  85         // fallback to the more general exception
  86         return new FileSystemException(file, other, errorString());
  87     }
  88 
  89     void rethrowAsIOException(String file) throws IOException {
  90         IOException x = translateToIOException(file, null);
  91         throw x;


  52 
  53     int lastError() {
  54         return lastError;
  55     }
  56 
  57     String errorString() {
  58         if (msg == null) {
  59             msg = WindowsNativeDispatcher.FormatMessage(lastError);
  60             if (msg == null) {
  61                 msg = "Unknown error: 0x" + Integer.toHexString(lastError);
  62             }
  63         }
  64         return msg;
  65     }
  66 
  67     @Override
  68     public String getMessage() {
  69         return errorString();
  70     }
  71 
  72     @Override
  73     public Throwable fillInStackTrace() {
  74         // This is an internal exception, the stack trace is irrelevant.
  75         // translateTo* methods would start the stack trace over.
  76         return this;
  77     }
  78 
  79     private IOException translateToIOException(String file, String other) {
  80         // not created with last error
  81         if (lastError() == 0)
  82             return new IOException(errorString());
  83 
  84         // handle specific cases
  85         if (lastError() == ERROR_FILE_NOT_FOUND || lastError() == ERROR_PATH_NOT_FOUND)
  86             return new NoSuchFileException(file, other, null);
  87         if (lastError() == ERROR_FILE_EXISTS || lastError() == ERROR_ALREADY_EXISTS)
  88             return new FileAlreadyExistsException(file, other, null);
  89         if (lastError() == ERROR_ACCESS_DENIED)
  90             return new AccessDeniedException(file, other, null);
  91 
  92         // fallback to the more general exception
  93         return new FileSystemException(file, other, errorString());
  94     }
  95 
  96     void rethrowAsIOException(String file) throws IOException {
  97         IOException x = translateToIOException(file, null);
  98         throw x;
< prev index next >