# Using Java.net Socket

**URL:** <https://forum.inductiveautomation.com/t/using-java-net-socket/79962>\
**Category:** Ignition\
**Tags:** scripting, ignition81\
**Created:** [October 3, 2023, 7:18am UTC](https://forum.inductiveautomation.com/t/using-java-net-socket/79962 "2023-10-03T07:18:02Z")\
**Posts on this page:** 1\
**Showing post:** 21

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 9, 2023, 2:56pm UTC](https://forum.inductiveautomation.com/t/using-java-net-socket/79962/21 "2023-10-09T14:56:03Z")

</div>

> [@victordcq](#):
>
> `except (JavaExpection, Exception), e:`

That won't catch everything. And it mixes data types for `e`. I use (and strongly recommend) this construct (shown as if a library script):

```auto
from java.lang import Throwable
logger = system.util.getLogger(system.util.getProjectName() + '.' + __name__ )

def someTask():
	try:
		someaction()
	except Throwable, t:
		# Throwable is the ultimate superclass of all java exceptions and errors
		logger.warn("some text for java", t)
	except Exception, e
		# Exception is python's superclass (technically BaseException--substitute if you like)
		logger.warn("some text for jython", later.PythonAsJavaException(e))

```

Note that you cannot use jython exceptions with loggers, and you should always be using loggers (no prints). Which is why the separate `except:` clause is so important--you have extra work required to log a python exception. (`PythonAsJavaException()` is available in my [later.py](https://www.automation-pros.com/ignition/later.py).)

If you have common handling needed for both exception cases, move that into another function.

---

_[View the full topic](https://forum.inductiveautomation.com/t/using-java-net-socket/79962)._
