Tüm Ürünler
Search
Belge Merkezi

Alibaba Cloud SDK:İstisna İşleme

Son Güncelleme:Oct 07, 2026

V2.0 SDK'deki istisna türlerini ve bunları nasıl işleyeceğinizi öğrenin.

İstisna Türleri

V2.0 SDK istisnaları şu türlere ayırır:

  • TeaUnretryableException: Tüm yeniden denemeler tükendiğinde ağ sorunları devam ediyorsa tetiklenir. Başarısız isteği incelemek için exception.getLastRequest yöntemini çağırın.

  • TeaException: Bir iş hatasını gösterir. Sorun gidermek için şu parametreleri kullanın:

    • code: OpenAPI iş hata kodu.

    • message: RequestId içeren hata mesajı.

    • data: Sunucunun döndürdüğü ayrıntılı hata bilgileri.

Önemli

Bu örnek yalnızca gösterim amaçlı çıktı verir. Üretim ortamında sistem kararlılığını sağlamak için istisnaları uygun şekilde ele alın; istisnaları yaygınlaştırın, günlüğe kaydedin veya kurtarma deneyin.

import com.aliyun.ecs20140526.models.DescribeRegionsRequest;
import com.aliyun.tea.TeaException;
import com.aliyun.tea.TeaUnretryableException;
import com.aliyun.tea.ValidateException;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.teautil.models.RuntimeOptions;

public class Sample {
    public static void main(String[] args) throws Exception {
        Config config = new com.aliyun.teaopenapi.models.Config();
        // Get the AccessKey ID of the RAM user from an environment variable.
        config.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"));
        // Get the AccessKey secret of the RAM user from an environment variable.
        config.setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        // The region ID.
        config.setRegionId("<regionId>");
        com.aliyun.ecs20140526.Client client = new com.aliyun.ecs20140526.Client(config);

        DescribeRegionsRequest describeRegionsRequest = new DescribeRegionsRequest();
        try {
            client.describeRegions(describeRegionsRequest);
        } catch(TeaUnretryableException ue) {
            // This is for demonstration only. Handle exceptions with caution and do not ignore them in your project.
            ue.printStackTrace();
            // Print the error message.
            System.out.println(ue.getMessage());
            // Print the request record.
            System.out.println(ue.getLastRequest());
        } catch (TeaException e) {
            // This is for demonstration only. Handle exceptions with caution and do not ignore them in your project.
            e.printStackTrace();
            // Print the error code.
            System.out.println(e.getCode());
            // Print the error message, which includes the RequestId.
            System.out.println(e.getMessage());
            // Print the specific content returned by the server.
            System.out.println(e.getData());
        }
    }
}

İstisnaları İşleme

API çağrı istisnalarını gidermek için:

  • İstisnadaki RequestId değerini kopyalayın ve nedeni belirlemek için OpenAPI Tanılama aracını kullanın. OpenAPI Tanılama.

  • Hata kodunu ilgili ürün belgelerinde arayın.

  • Çözüm için SSS bölümünü kontrol edin.

  • Teknik destek ile iletişime geçin.