How to terminate a running script completely II

Hello,

I found different discussions, but none of them are helpful for my problem.

I build some common libraries that are used with include and I want to show a message when a user try to run such a script that this library is not intended to run for itself.

//==============================================================================// S C R I P T   W A R N I N G//==============================================================================if (getScriptFileName().search("m42Logfile.ds") > 0){   MessageBox.information(qsTr("This script is a library used by other scripts and can't be executed."), qsTr("Library - Information"), qsTr("&OK"));   exit(); // I NEED TO LEAVE HERE}//==============================================================================//==============================================================================// I N C L U D E//==============================================================================include(scriptPath + "m42Project" + m42ScriptExt);

I need to leave the script after I show the message (the line where I tried exit() (and break or return)) without success.

The reason is that the include line(s) refer zur 2 variables that are defined in the main script before including the lib. And if the script is not "left" before this line it throws an error.

(An anonymous function doesn't work for obvious resasons)

Any idea how to break/stop/quit/exit the script at a specific line?

Thanks in advance for any hint.

With kind regards,

Ruediger Kabbasch

Sure, I can put the include lines into a function, but that forces me to call this routine in almost every routine I define in the script (or at least in a number of routines).

 

Comments

  • ruekakaruekaka Posts: 346
    ruekaka said:

    Sure, I can put the include lines into a function, but that forces me to call this routine in almost every routine I define in the script (or at least in a number of routines).

    Sorry this line was intended to be a few lines earlier. 

  • ruekakaruekaka Posts: 346

    O.K. I found a way to handle it, not the nicest one, but for now it's O.K.

    try{   include(m42ScriptPath + "m42Project" + m42ScriptExt);   // . . . }catch (Exception){}

     

Sign In or Register to comment.