<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <div class="moz-cite-prefix">On 5/2/22 9:36 PM, Stephen Sacks via
      Qgis-user wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:c6c08270-0ecd-0f17-3e2c-9f9eb70d4eb4@gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <font size="4">I would like to terminate a Python script
        gracefully.  Both quit() and exit() not only abort the script
        but end the entire QGIS app.</font></blockquote>
    <p><br>
      <font size="4">Assuming the script runs as a QGIS p</font><font
        size="4">lugin, a better </font><font size="4">alternative is
        to raise an exception, which wi</font><font size="4">l</font><font
        size="4">l be reported in the QGIS messages tab.</font></p>
    <p><font size="4">c</font><font size="4">lass MyP</font><font
        size="4">luginException:<br>
            pass</font></p>
    <p><font size="4">if not fi</font><font size="4">lePath.is_fi</font><font
        size="4">le():<br>
            # This </font><font size="4">line shou</font><font size="4">ld
        cause the exception message and<br>
            # a stack trace be reported in the QGIS messages window.</font><br>
      <font size="4"><font size="4"></font>    raise MyP</font><font
        size="4">luginException("Unab</font><font size="4">le to find fi</font><font
        size="4">le %s" % fName)<br>
      </font></p>
    <p><font size="4"><br>
        I remember using QgsMessageBar [1] once to provide better cues
        in the QGIS UI.  It generates a message bar with background
        color set according to the severity of the message (info,
        warning, error).<br>
        <br>
        Hope that helps.<br>
        <br>
        Asim<br>
      </font></p>
    <p><font size="4">[1]
<a class="moz-txt-link-freetext" href="https://qgis.org/pyqgis/master/gui/QgsMessageBar.html?highlight=qgsmessagebar#qgis.gui.QgsMessageBar.pushMessage">https://qgis.org/pyqgis/master/gui/QgsMessageBar.html?highlight=qgsmessagebar#qgis.gui.QgsMessageBar.pushMessage</a><br>
      </font><font size="4"></font></p>
    <br>
  </body>
</html>