# Problems with Exception Handling

**URL:** <https://discourse.processing.org/t/problems-with-exception-handling/22302>\
**Category:** Libraries\
**Created:** [July 1, 2020, 3:50pm UTC](https://discourse.processing.org/t/problems-with-exception-handling/22302 "2020-07-01T15:50:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![raphael](https://avatars.discourse-cdn.com/v4/letter/r/edb3f5/32.png) [@raphael](https://discourse.processing.org/u/raphael)\
**Post date:** [July 1, 2020, 3:50pm UTC](https://discourse.processing.org/t/problems-with-exception-handling/22302/1 "2020-07-01T15:50:31Z")

</div>

In my project I need to make a socket connection, however I realized that there is a chance that the user will not start the server. When this happens, it is obvious that the client will not be able to connect to the server. I wanted my application to be able to handle this exception. However, it seems that processing is unable to “catch” the exception.

my code:

```auto
  try {
      myClient = new Client(this, "127.0.0.1", 8000);
  } catch (Exception e) {
      //print(e);
      print("I stopped by to say hi!!!");
      exit();
  }

```

what the processing terminal returns is this:

```auto
java.net.ConnectException: Conexão recusada (Connection refused)
   at java.net.PlainSocketImpl.socketConnect(Native Method)
   at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
   at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
   at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
   at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
   at java.net.Socket.connect(Socket.java:589)
   at java.net.Socket.connect(Socket.java:538)
   at java.net.Socket.<init>(Socket.java:434)
   at java.net.Socket.<init>(Socket.java:211)
   at processing.net.Client.<init>(Unknown Source)
   at INSHRDLU.setup(INSHRDLU.java:25)
   at processing.core.PApplet.handleDraw(PApplet.java:2432)
   at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1547)
   at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:313)

```

**My question is:**

> What am I doing wrong?
