//snippet-sourcedescription:[ListTopics.java demonstrates how to get a list of existing AWS SNS topics.]
//snippet-keyword:[Java]
//snippet-sourcesyntax:[java]
//snippet-keyword:[Code Sample]
//snippet-keyword:[Amazon Simple Notification Service]
//snippet-service:[sns]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[2019-07-20]
//snippet-sourceauthor:[jschwarzwalder AWS]
/*
 * Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
//snippet-start:[sns.java2.ListTopics.complete]
package com.example.sns;

//snippet-start:[sns.java2.ListTopics.import]

import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.sns.SnsClient;
import software.amazon.awssdk.services.sns.model.ListTopicsRequest;
import software.amazon.awssdk.services.sns.model.ListTopicsResponse;
//snippet-end:[sns.java2.ListTopics.import]

public class ListTopics {
    public static void main(String[] args) {
        final String USAGE = "\n" +
                "ListTopics - returns a list of Amazon SNS topics.\n" +
                "Usage: ListTopics \n\n";


        //snippet-start:[sns.java2.ListTopics.main]

        SnsClient snsClient = SnsClient.builder().region(Region.US_EAST_1).build();

        ListTopicsRequest request = ListTopicsRequest.builder().build();

        ListTopicsResponse result = snsClient.listTopics(request);

        System.out.println("Status was " + result.sdkHttpResponse().statusCode() + "\n\nTopics\n\n" + result.topics());
        //snippet-end:[sns.java2.ListTopics.main]
    }
}
//snippet-end:[sns.java2.ListTopics.complete]


@@ -362,28 +362,23 @@
 or:%5B
-j
 sc
-hwarzwalder
+macdon
  AWS%5D%0A
+%0A
 /*%0A 
@@ -396,18 +396,18 @@
  2010-20
-19
+20
  Amazon.
@@ -1078,17 +1078,16 @@
 import%5D%0A
-%0A
 import s
@@ -1315,16 +1315,79 @@
 sponse;%0A
+import software.amazon.awssdk.services.sns.model.SnsException;%0A
 //snippe
@@ -1645,17 +1645,16 @@
 %5Cn%5Cn%22;%0A%0A
-%0A
         
@@ -1697,17 +1697,16 @@
 s.main%5D%0A
-%0A
         
@@ -1746,16 +1746,33 @@
 uilder()
+%0A                
 .region(
@@ -1785,15 +1785,32 @@
 .US_
+W
 E
-A
 ST_
-1)
+2)%0A                
 .bui
@@ -1808,32 +1808,50 @@
      .build();%0A%0A
+        try %7B%0A    
         ListTopi
@@ -1897,16 +1897,37 @@
 uilder()
+%0A                    
 .build()
@@ -1929,32 +1929,36 @@
 ild();%0A%0A        
+  
+  
 ListTopicsRespon
@@ -2000,17 +2000,20 @@
 quest);%0A
-%0A
+    
         
@@ -2124,16 +2124,144 @@
 ics());%0A
+%0A    %7D catch (SnsException e) %7B%0A%0A        System.err.println(e.awsErrorDetails().errorMessage());%0A        System.exit(1);%0A    %7D%0A%0A
         
@@ -2356,9 +2356,8 @@
 mplete%5D%0A
-%0A

Update ListTopics.java