Skip to content

Commit 04cea82

Browse files
committed
QNFile add try.. catch.. when reading file
1 parent 6883fe6 commit 04cea82

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

QiniuSDK/Common/QNFile.m

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,21 @@ - (instancetype)init:(NSString *)path
7777

7878
- (NSData *)read:(long)offset
7979
size:(long)size {
80+
8081
NSData *data = nil;
81-
[_lock lock];
82-
if (_data != nil) {
83-
data = [_data subdataWithRange:NSMakeRange(offset, (unsigned int)size)];
84-
} else {
85-
[_file seekToFileOffset:offset];
86-
data = [_file readDataOfLength:size];
82+
@try {
83+
[_lock lock];
84+
if (_data != nil) {
85+
data = [_data subdataWithRange:NSMakeRange(offset, (unsigned int)size)];
86+
} else {
87+
[_file seekToFileOffset:offset];
88+
data = [_file readDataOfLength:size];
89+
}
90+
} @catch (NSException *exception) {
91+
NSLog(@"read file failed reason: %@ \n%@", exception.reason, exception.callStackSymbols);
92+
} @finally {
93+
[_lock unlock];
8794
}
88-
[_lock unlock];
8995
return data;
9096
}
9197

0 commit comments

Comments
 (0)