Raise Exception not working with Python

Running OL Workflow 2023.2.2 with Python 3.11. According to Terminating script execution

I should be able to terminate script execution and go the On Error handling of the task. It stops script execution but it continues the process although I set it to this:

Can you please confirm whether the following is not the case?

In Python, the raise statement is similar to JavaScript and will stop processing and trigger the On Error tab unless an except statement is used.

Source: Terminating script execution - OL Connect Workflow 2024.1 Help

No except statement, just a raise.

Would you mind sharing the applied Python code?

*

* Imports

import sys
import importlib

sys.path.append(“C:\PPConfig\Scripts”)
u = importlib.import_module(“util”)

*

* Register job in db

util = u.Util(Watch, Script)
dbConnection = util.dbConnection
dbCursor = util.dbCursor

try:
# register job
dbCursor.execute(
“”“INSERT INTO [dbo].[job] ([j_is_finished_ok],[j_created_at],[j_updated_at],[j_input_channel],[j_input_file_url],[j_input_file_owner]) OUTPUT INSERTED.[j_id] VALUES (0,sysdatetime(),sysdatetime(),?,?,?)”“”,
(“none”, “none”, “PP Workflow”),
)
# get uid from db (autoincrement PK)
dbCursor.execute(“SELECT @@IDENTITY AS ID;”)
id = dbCursor.fetchone()[0]
dbConnection.commit()
# create job step
dbCursor.execute(
“”“INSERT INTO [dbo].[job_processed_step] ([jps_j_id],[jps_created_at],[jps_is_finished_ok],[jps_step_name],[jps_remarks]) VALUES (?,sysdatetime(),1,?,?)”“”,
(id, “createGuid”, “none”),
)
dbConnection.commit()
mailingId = str(id)
Script.ReturnValue = 1
except Exception as ex:
Watch.Log("DB dbConnection issue: " + ex.args[1], 2)
Script.ReturnValue = 0

Watch.Log(“TEST1”,2)
Watch.SetVariable(“mailingId”, mailingId)
Watch.SetJobInfo(1, mailingId)
Watch.SetJobInfo(2, “Error 12345”)
Watch.Log(“TEST2”,2)
raise Exception(“Helaas”)
Watch.Log(“TEST3”,2)

It does end processing after “TEST2” but the raise doesn’t reach PP Workflow somehow?

I have not been able to replicate your issue.

Using the following Advanced properties for my script task:

When the raise statement is executed, the script immediately exits with the actual Python Error, the additional Stopping because of error message is logged as well, and the process is stopped:

image

Nice! My config gives me this:

using this script (part):
Watch.Log(“TEST1”,2)
Watch.SetVariable(“mailingId”, mailingId)
Watch.SetJobInfo(1, mailingId)
Watch.SetJobInfo(2, “Error 12345”)
Watch.Log(“TEST2”,2)
Watch.Log(“Helaas”,1)
raise Exception(“Helaas”)
Watch.Log(“TEST3”,2)

Using the same Advanced properties:

Could this have something to do with the Python version? I’m using 3.11.

Try using raise ValueError('Helaas') or raise NameError('Helaas') instead of using the Exception() root class.

That did the trick! Thx :slight_smile: