Python macro: How to interrupt script execution (like "End" in BASIC)

Hello everyone!
Searching for python-script interruption way, like “End” in Basic.
as an option is to throw new Exception with custom message, something like:
create_instance(“com.sun.star.uno.RuntimeException”, ctx)
or
create_instance("com.sun.star.uno.RuntimeException((string)message …)

but how to build new uno-Exception from python ?
or any similar function for “End”?

any suggestions?

Hallo
raise

raise Exception triggers dialog box in LibreOffice with tons of exception description.

Searching for silent stop execution or exception with custom message …

Thank you for quick reply…

    if »something happens«:
        return

which returns to the calling routine.
Return some value that is not expected to be returned (string instead of number)

ret = other_routine
if ret == 'Put and end to this!':
   return ret

“return” just stops current function, in that situation I I don’t wanna handle chain of returns from invoked functions…

need End whole macro/script

Does quit() work within a def?

sys.exit() , quit() - are Python functions, they trigger weird Exceptions in LibreOffice.

the solution should be to call certain uno-object or uno-service …

please give us more context!
? did you already read the whole Chapter about raise ?

yes I did.

searching the way to manage LibreOffice Error message or silent exit from script…

Where & how to file enhancement requests, please?

see also Running Scripts separately from the LibreOffice process,
ScriptForge.Exception service (SF_Exception)

thats a bold lie!
python, of couse, can run without soffice invoked, but not via some weird sf-Service

Call main.

def main():
    try:
        practice(50) 
    except Exception as e:
        print(f"Error: {e}")


def practice(arg=100):
    raise Exception("Hello World")

2 Likes

Yup ! that’s what I did !
just wanted to avoid those try-catches…

ScriptForge:
SF_Exception.Raise(…) - for Basic only !

for Python:
SF_Exception.DebugPrint(“Value of someVar”, someVar)
SF_Exception.Console()

  • nice debug windows but no Raise() method/interruption for python …

thanks sokol92

1 Like