Fail ignoring java.lang.IllegalStateException Error

I want to Ignore an error, I tried using: try: except: schema.

I’m using the system.gui.transform() in:

import java
try:
system.gui.transform(component=event.source, newWidth=100, duration=2000, callback=lambda: system.gui.transform(component=event.source, newWidth=200))
except java.lang.IllegalStateException:
print ‘Do nothing’

But error persists
image

please help

The lambda isn’t running in the context of the try. It’s running in the callback context. You’ll probably have to use a full function definition with a nested try: catch: construct instead of a lambda.

sir @pturmel. Can you please tell me how?

If I understood…
def callbackCatch():
try:
system.gui.transform(component=event.source, newWidth=200)
except:
print ‘Do nothing and close def’


system.gui.transform(component=event.source, newWidth=100, duration=2000, callback=callbackCatch())

like that??
I already tried it but the callback never happens!!

Mr. @pturmel is there a difference between catch: and except:?

Thanks for reply!!

Sorry “catch” is what other languages use. Python uses “except”. I think your only mistake is putting a pair of parentheses on callbackCatch where you use it. When passing a function to be called later, leave off the parentheses.

And please edit your posts to use code formatting blocks, using triple backquotes, like so:
```
pasted code
```

1 Like

Thanks Mr. @pturmel, it works like a charm

print 'Thanks' 
3 Likes