< prev index next >

src/java.base/unix/classes/sun/nio/fs/UnixException.java

Print this page




  53     }
  54 
  55     void setError(int errno) {
  56         this.errno = errno;
  57         this.msg = null;
  58     }
  59 
  60     String errorString() {
  61         if (msg != null) {
  62             return msg;
  63         } else {
  64             return Util.toString(UnixNativeDispatcher.strerror(errno()));
  65         }
  66     }
  67 
  68     @Override
  69     public String getMessage() {
  70         return errorString();
  71     }
  72 







  73     /**
  74      * Map well known errors to specific exceptions where possible; otherwise
  75      * return more general FileSystemException.
  76      */
  77     private IOException translateToIOException(String file, String other) {
  78         // created with message rather than errno
  79         if (msg != null)
  80             return new IOException(msg);
  81 
  82         // handle specific cases
  83         if (errno() == UnixConstants.EACCES)
  84             return new AccessDeniedException(file, other, null);
  85         if (errno() == UnixConstants.ENOENT)
  86             return new NoSuchFileException(file, other, null);
  87         if (errno() == UnixConstants.EEXIST)
  88             return new FileAlreadyExistsException(file, other, null);
  89         if (errno() == UnixConstants.ELOOP)
  90             return new FileSystemException(file, other, errorString()
  91                 + " or unable to access attributes of symbolic link");
  92 




  53     }
  54 
  55     void setError(int errno) {
  56         this.errno = errno;
  57         this.msg = null;
  58     }
  59 
  60     String errorString() {
  61         if (msg != null) {
  62             return msg;
  63         } else {
  64             return Util.toString(UnixNativeDispatcher.strerror(errno()));
  65         }
  66     }
  67 
  68     @Override
  69     public String getMessage() {
  70         return errorString();
  71     }
  72 
  73     @Override
  74     public Throwable fillInStackTrace() {
  75         // This is an internal exception, the stack trace is irrelevant.
  76         // translateTo* methods would start the stack trace over.
  77         return this;
  78     }
  79 
  80     /**
  81      * Map well known errors to specific exceptions where possible; otherwise
  82      * return more general FileSystemException.
  83      */
  84     private IOException translateToIOException(String file, String other) {
  85         // created with message rather than errno
  86         if (msg != null)
  87             return new IOException(msg);
  88 
  89         // handle specific cases
  90         if (errno() == UnixConstants.EACCES)
  91             return new AccessDeniedException(file, other, null);
  92         if (errno() == UnixConstants.ENOENT)
  93             return new NoSuchFileException(file, other, null);
  94         if (errno() == UnixConstants.EEXIST)
  95             return new FileAlreadyExistsException(file, other, null);
  96         if (errno() == UnixConstants.ELOOP)
  97             return new FileSystemException(file, other, errorString()
  98                 + " or unable to access attributes of symbolic link");
  99 


< prev index next >