<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: errors using python.exe in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/errors-using-python-exe/m-p/9239#M744</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That is so cool! thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 25 Apr 2014 21:02:28 GMT</pubDate>
    <dc:creator>AmyKlug</dc:creator>
    <dc:date>2014-04-25T21:02:28Z</dc:date>
    <item>
      <title>errors using python.exe</title>
      <link>https://community.esri.com/t5/python-questions/errors-using-python-exe/m-p/9235#M740</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If I run my python code using a text file via python.exe from windows desktop (open with) or task scheduler, is there a way to see if there were any errors? would a try/except work?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Apr 2014 20:15:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/errors-using-python-exe/m-p/9235#M740</guid>
      <dc:creator>AmyKlug</dc:creator>
      <dc:date>2014-04-25T20:15:46Z</dc:date>
    </item>
    <item>
      <title>Re: errors using python.exe</title>
      <link>https://community.esri.com/t5/python-questions/errors-using-python-exe/m-p/9236#M741</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;A try/except block would do this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Maybe something along these lines.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import traceback

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; Your Code Here

except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; outfile = open("error.txt","w")
&amp;nbsp;&amp;nbsp;&amp;nbsp; outfile.write(traceback.format_exc())
&amp;nbsp;&amp;nbsp;&amp;nbsp; outfile.close()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:22:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/errors-using-python-exe/m-p/9236#M741</guid>
      <dc:creator>MattEiben</dc:creator>
      <dc:date>2021-12-10T20:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: errors using python.exe</title>
      <link>https://community.esri.com/t5/python-questions/errors-using-python-exe/m-p/9237#M742</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;A try/except block would do this.&lt;BR /&gt;Maybe something along these lines.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import traceback

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; Your Code Here

except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; outfile = open("error.txt","w")
&amp;nbsp;&amp;nbsp;&amp;nbsp; outfile.write(traceback.format_exc())
&amp;nbsp;&amp;nbsp;&amp;nbsp; outfile.close()&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks that worked!!!!!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;now.......&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you know of a way to add the error as a message to the python.exe window the code is running and have the window stay open instead of closing? the same as if you run a tool that errors in arcmap and you do NOT check "close this dialog when completed successfully"?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:22:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/errors-using-python-exe/m-p/9237#M742</guid>
      <dc:creator>AmyKlug</dc:creator>
      <dc:date>2021-12-10T20:22:37Z</dc:date>
    </item>
    <item>
      <title>Re: errors using python.exe</title>
      <link>https://community.esri.com/t5/python-questions/errors-using-python-exe/m-p/9238#M743</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yep, just use "finally" as part of your try/except/finally block.&amp;nbsp; The finally code executes no matter what after your code goes through the try/except.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import traceback&amp;nbsp; try: &amp;nbsp;&amp;nbsp;&amp;nbsp; Your Code Here&amp;nbsp; except: &amp;nbsp;&amp;nbsp;&amp;nbsp; traceback.print_exc()&amp;nbsp; finally: &amp;nbsp;&amp;nbsp;&amp;nbsp; raw_input("Press any key to close this window")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Apr 2014 20:49:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/errors-using-python-exe/m-p/9238#M743</guid>
      <dc:creator>MattEiben</dc:creator>
      <dc:date>2014-04-25T20:49:29Z</dc:date>
    </item>
    <item>
      <title>Re: errors using python.exe</title>
      <link>https://community.esri.com/t5/python-questions/errors-using-python-exe/m-p/9239#M744</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That is so cool! thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Apr 2014 21:02:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/errors-using-python-exe/m-p/9239#M744</guid>
      <dc:creator>AmyKlug</dc:creator>
      <dc:date>2014-04-25T21:02:28Z</dc:date>
    </item>
    <item>
      <title>Re: errors using python.exe</title>
      <link>https://community.esri.com/t5/python-questions/errors-using-python-exe/m-p/9240#M745</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I just tested this on code with no errors. how can I get the python window only stay open when there are errors?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT: I figured it out&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Box stays open with and without errors:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; traceback.print_exc()
&amp;nbsp;&amp;nbsp;&amp;nbsp; raw_input("ERRORS OCCURRED")

finally:
&amp;nbsp;&amp;nbsp;&amp;nbsp; raw_input("Update Successful")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Box closes if no errors:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; traceback.print_exc()
&amp;nbsp;&amp;nbsp;&amp;nbsp; raw_input("ERRORS OCCURRED")
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:22:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/errors-using-python-exe/m-p/9240#M745</guid>
      <dc:creator>AmyKlug</dc:creator>
      <dc:date>2021-12-10T20:22:40Z</dc:date>
    </item>
  </channel>
</rss>

