Changeset 1708
- Timestamp:
- 07/01/10 21:14:49 (14 years ago)
- Files:
-
- trunk/phobos/std/file.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/phobos/std/file.d
r1639 r1708 125 125 */ 126 126 127 127 class FileException : Exception 128 128 { 129 129 /** 130 130 OS error code. 131 131 */ 132 132 immutable uint errno; 133 133 134 134 /** 135 Constructor taking the name of the file where error happened and the 136 error number ($(LUCKY GetLastError) in Windows, $(D getErrno) in 137 Posix). 135 Constructor taking the name of the file where error happened and a 136 message describing the error. 138 137 */ 139 138 this(in char[] name, in char[] message) 140 139 { 141 140 super(text(name, ": ", message)); 141 errno = 0; 142 } 143 144 this(in char[] name, in char[] message, string sourceFile, int sourceLine) 145 { 146 super(text(name, ": ", message), sourceFile, sourceLine); 142 147 errno = 0; 143 148 } 144 149 145 150 /** 146 151 Constructor taking the name of the file where error happened and the 147 152 error number ($(LUCKY GetLastError) in Windows, $(D getErrno) in 148 153 Posix). 149 154 */ 150 version(Windows) this( stringname, uint errno = GetLastError)155 version(Windows) this(in char[] name, uint errno = GetLastError) 151 156 { 152 157 this(name, sysErrorString(errno)); 153 158 this.errno = errno; 154 159 } 155 160 156 161 version(Posix) this(in char[] name, uint errno = .getErrno) 157 162 { 158 163 auto s = strerror(errno); 159 164 this(name, to!string(s)); 160 165 this.errno = errno; 161 166 } 167 168 version(Windows) this(in char[] name, string sourceFile, int sourceLine, 169 uint errno = GetLastError) 170 { 171 this(name, sysErrorString(errno), sourceFile, sourceLine); 172 this.errno = errno; 173 } 174 175 version(Posix) this(in char[] name, string sourceFile, int sourceLine, 176 uint errno = .getErrno) 177 { 178 auto s = strerror(errno); 179 this(name, to!string(s), sourceFile, sourceLine); 180 this.errno = errno; 181 } 162 182 } 163 183 164 184 private T cenforce(T, string file = __FILE__, uint line = __LINE__) 165 185 (T condition, lazy const(char)[] name) 166 186 { 167 187 if (!condition) 168 188 { 169 throw new FileException( 170 text("In ", file, "(", line, "), data file ", name)); 189 throw new FileException(name, file, line); 171 190 } 172 191 return condition; 173 192 } 174 193 175 194 /* ********************************** 176 195 * Basic File operations. 177 196 */ 178 197 179 198 /******************************************** 180 199 Read entire contents of file $(D name).
