iOS Amazon S3客户端 - 如何处理“请求超时”

时间:2014-07-29 00:02:05

标签: ios amazon-web-services amazon-s3

我收到了很多这些崩溃报告:

Fatal Exception: AmazonClientException
Request timed out.

Thread : Fatal Exception: AmazonClientException
0  CoreFoundation                 0x2e2cdf83 __exceptionPreprocess + 130
1  libobjc.A.dylib                0x38a7eccf objc_exception_throw + 38
2  MyApp                          0x002b8605 +[AmazonErrorHandler errorFromException:serviceErrorDomain:clientErrorDomain:]
3  MyApp                          0x0024af5d -[AmazonS3Client invoke:] (AmazonS3Client.m:549)
4  MyApp                          0x00249721 -[AmazonS3Client putObject:] (AmazonS3Client.m:134)
5  MyApp                          0x000e9d0b -[MyAppAmazonClient uploadObject:async:contentType:path:bucket:type:username:update:success:failure:] (MyAppAmazonClient.m:199)
6  MyApp                          0x000e998f -[MyAppAmazonClient uploadObject:async:contentType:path:type:username:update:success:failure:] (MyAppAmazonClient.m:150)
7  MyApp                          0x000e962d -[MyAppAmazonClient tryUploadObject:async:contentType:path:type:username:update:success:failure:] (MyApp AmazonClient.m:121)
8  MyApp                          0x001ee233 -[SomeOperation uploadFile:] (SomeOperation.m:148)
9  MyApp                          0x001edf6b -[SomeOperation performServerUploadFiles] (SomeOperation.m:127)
10 MyApp                          0x001ed22f -[SomeOperation main] (SomeOperation.m:50)
11 Foundation                     0x2ec025ab -[__NSOperationInternal _start:] + 770
12 Foundation                     0x2eca676d __NSOQSchedule_f + 60
13 libdispatch.dylib              0x38f689ab _dispatch_async_redirect_invoke$VARIANT$up + 110
14 libdispatch.dylib              0x38f79921 _dispatch_root_queue_drain + 224
15 libdispatch.dylib              0x38f79b21 _dispatch_worker_thread2 + 56
16 libsystem_pthread.dylib        0x390a8bd3 _pthread_wqthread + 298
17 libsystem_pthread.dylib        0x390a8a98 start_wqthread + 8

发生错误的代码行是:

S3PutObjectResponse *response = [self.s3 putObject:putObjectRequest]; //ERROR HERE

if(response.error != nil)
        {
            NSLog(@"Amazon Client Error: %@", response.error);
        }


        if (response.exception) {
            if (theRequest.failureBlock) {
                theRequest.failureBlock([response description]);
            }
        }
        else if (scRequest.successBlock) {
            //success
        }

问题在于超时发生,因此我没有机会处理任何错误或例外。

我可以在哪里放置代码来处理请求超时,以便应用程序不会崩溃?

只有当请求超时时才会发生崩溃。

1 个答案:

答案 0 :(得分:1)

您正在调用的AmazonS3Client方法抛出了Objective-C异常。 Catch it using @try / @catch.