MCPcopy Index your code
hub / github.com/ccxt/ccxt / main

Method main

java/examples/src/main/java/examples/ErrorHandling.java:18–64  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

16public class ErrorHandling {
17
18 public static void main(String[] args) {
19 Binance exchange = new Binance();
20
21 exchange.loadMarkets(false);
22
23 // 1. Handle bad symbol
24 System.out.println("--- Test 1: Invalid symbol ---");
25 try {
26 exchange.fetchTicker("INVALID/NOTEXIST");
27 } catch (CompletionException e) {
28 Throwable cause = unwrap(e);
29 if (cause instanceof BadSymbol) {
30 System.out.println("Caught BadSymbol: " + cause.getMessage());
31 } else if (cause instanceof ExchangeError) {
32 System.out.println("Caught ExchangeError: " + cause.getMessage());
33 } else {
34 System.out.println("Caught: " + cause.getClass().getSimpleName() + ": " + cause.getMessage());
35 }
36 }
37
38 // 2. Handle authentication error
39 System.out.println("\n--- Test 2: Auth required without credentials ---");
40 try {
41 exchange.fetchBalance((Map<String, Object>) null);
42 } catch (CompletionException e) {
43 Throwable cause = unwrap(e);
44 if (cause instanceof AuthenticationError) {
45 System.out.println("Caught AuthenticationError: " + shorten(cause.getMessage()));
46 } else if (cause instanceof ExchangeError) {
47 System.out.println("Caught ExchangeError: " + shorten(cause.getMessage()));
48 } else {
49 System.out.println("Caught: " + cause.getClass().getSimpleName() + ": " + shorten(cause.getMessage()));
50 }
51 }
52
53 // 3. Successful request
54 System.out.println("\n--- Test 3: Successful ticker fetch ---");
55 try {
56 Ticker ticker = exchange.fetchTicker("BTC/USDT");
57 System.out.println("Success: BTC/USDT last=" + ticker.last);
58 } catch (CompletionException e) {
59 Throwable cause = unwrap(e);
60 System.out.println("Unexpected error: " + cause.getMessage());
61 }
62
63 System.out.println("\nAll error handling tests completed.");
64 }
65
66 static Throwable unwrap(Throwable t) {
67 while ((t instanceof CompletionException || t instanceof java.util.concurrent.ExecutionException)

Callers

nothing calls this directly

Calls 5

loadMarketsMethod · 0.95
fetchTickerMethod · 0.95
unwrapMethod · 0.95
fetchBalanceMethod · 0.95
shortenMethod · 0.95

Tested by

no test coverage detected