# Jython exception syntax error

**URL:** <https://forum.inductiveautomation.com/t/jython-exception-syntax-error/88434>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [April 5, 2024, 3:17pm UTC](https://forum.inductiveautomation.com/t/jython-exception-syntax-error/88434 "2024-04-05T15:17:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zach\_Larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zach_larson/32/54388_2.png) [@Zach\_Larson](https://forum.inductiveautomation.com/u/Zach_Larson)\
**Post date:** [April 5, 2024, 3:17pm UTC](https://forum.inductiveautomation.com/t/jython-exception-syntax-error/88434/1 "2024-04-05T15:17:02Z")

</div>

Topic got moved.  
Was attempting code from the other thread.  
Tried to delete this topic, can't.  
Someone please delete.

---

<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:** [April 5, 2024, 3:22pm UTC](https://forum.inductiveautomation.com/t/jython-exception-syntax-error/88434/2 "2024-04-05T15:22:59Z")

</div>

You have colon after the `except` keyword **and** at the end of the line. The first one doesn't belong. ~~(And why is this in this topic?)~~ _Moved to a new topic._

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [April 5, 2024, 3:23pm UTC](https://forum.inductiveautomation.com/t/jython-exception-syntax-error/88434/3 "2024-04-05T15:23:18Z")

</div>

```auto
from java.lang import Exception as JavaError
logger = system.util.getLogger("yourLoggerName")

try:
    test = 1/0
except JavaError, je:
    logger.warn("An error occurred", e)
except Exception, e:
    logger.warnf("An error occurred: %s", e)

```

I now recommend that you use Throwable instead, all Java Exceptions are derived from the Throwable interface so it is more verbose in what it catches.

```auto
from java.lang import Throwable
logger = system.util.getLogger("yourLoggerName")

try:
   test = 1/0
except Throwable, t:
    logger.warn("An error occurred", t)
except Exception, e:
    logger.warn("An error occurred", e)

```

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [April 5, 2024, 3:29pm UTC](https://forum.inductiveautomation.com/t/jython-exception-syntax-error/88434/5 "2024-04-05T15:29:32Z")

</div>

In the snippet you've provided I do not see where you have included the import. You must import the Java Type to use it.

---

<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:** [April 5, 2024, 3:36pm UTC](https://forum.inductiveautomation.com/t/jython-exception-syntax-error/88434/6 "2024-04-05T15:36:57Z")

</div>

> [@lrose](#):
>
> ```auto
> except Exception, e:
> logger.warn("An error occurred", e)
> 
> ```

You cannot put jython exceptions into loggers. Use `PythonAsJavaException()` to wrap them.

---

<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:** [April 5, 2024, 3:55pm UTC](https://forum.inductiveautomation.com/t/jython-exception-syntax-error/88434/7 "2024-04-05T15:55:44Z")

</div>

`PythonAsJavaException` can be found in my [later.py](https://www.automation-pros.com/ignition/later.py) script.
