MCPcopy Create free account
hub / github.com/github/awesome-copilot / ErrorHandling

Class ErrorHandling

cookbook/copilot-sdk/java/recipe/ErrorHandling.java:9–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7import java.util.concurrent.ExecutionException;
8
9public class ErrorHandling {
10 public static void main(String[] args) {
11 try (var client = new CopilotClient()) {
12 client.start().get();
13
14 try (var session = client.createSession(
15 new SessionConfig()
16 .setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
17 .setModel("gpt-5")).get()) {
18
19 session.on(AssistantMessageEvent.class,
20 msg -> System.out.println(msg.getData().content()));
21
22 session.sendAndWait(
23 new MessageOptions().setPrompt("Hello!")).get();
24 }
25 } catch (ExecutionException ex) {
26 Throwable cause = ex.getCause();
27 Throwable error = cause != null ? cause : ex;
28 System.err.println("Error: " + error.getMessage());
29 error.printStackTrace();
30 } catch (InterruptedException ex) {
31 Thread.currentThread().interrupt();
32 System.err.println("Interrupted: " + ex.getMessage());
33 ex.printStackTrace();
34 } catch (Exception ex) {
35 System.err.println("Error: " + ex.getMessage());
36 ex.printStackTrace();
37 }
38 }
39}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected