[Qgis-user] quit() and exit()

2022-05-03 Thread Stephen Sacks via Qgis-user
In case there may be someone out there who is interested in my question, below is Asim's answer (with one correction he made).    When run in the Python console, this code causes execution of the script to stop and a window to pop up titled "Execution error" with my explanatory message.  And, u

Re: [Qgis-user] quit() and exit()

2022-05-03 Thread Asim via Qgis-user
Hi Stephen You are welcome!  Please see my response below. On 5/3/22 2:33 AM, Stephen Sacks wrote: Hi Asim,    Thanks for your help.  But I have no experience with raising an exception, so I need more help.   I ran the following 7 lines of code in the Python console in Qgis: fName = 'xyz' v

Re: [Qgis-user] quit() and exit()

2022-05-02 Thread Asim via Qgis-user
On 5/2/22 9:36 PM, Stephen Sacks via Qgis-user wrote: I would like to terminate a Python script gracefully.  Both quit() and exit() not only abort the script but end the entire QGIS app. Assuming the script runs as a QGIS plugin, a better alternative is to raise an exception, which will be re

Re: [Qgis-user] quit() and exit()

2022-05-02 Thread Raymond Nijssen via Qgis-user
Put your code in a main() function and use return to leave the function? On 02-05-2022 18:06, Stephen Sacks via Qgis-user wrote: I would like to terminate a Python script gracefully.  Both quit() and exit() not only abort the script but end the entire QGIS app.  For example, if a file I want t

[Qgis-user] quit() and exit()

2022-05-02 Thread Stephen Sacks via Qgis-user
I would like to terminate a Python script gracefully.  Both quit() and exit() not only abort the script but end the entire QGIS app.  For example, if a file I want to read doesn't exist, the following four lines of code terminate QGIS: filePath = Path(fName) if not filePath.is_file():     prin