<?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: How to Raise Statements/Handle Errors and Exceptions in a Python Addin? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/raising-exceptions-in-a-python-thread/m-p/256096#M19695</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks!;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Now thats a lesson in indentation I hopefully won't forget..&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 27 May 2013 06:52:04 GMT</pubDate>
    <dc:creator>ColinConstance</dc:creator>
    <dc:date>2013-05-27T06:52:04Z</dc:date>
    <item>
      <title>Raising exceptions in a Python thread</title>
      <link>https://community.esri.com/t5/python-questions/raising-exceptions-in-a-python-thread/m-p/256094#M19693</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Ok I'm a newbie in this area so I need to understand how exceptions are raised...&lt;BR /&gt;Below is my Add-in code which is essentially the example for a button on a toolbar in the ArcGIS 10.1 Python wizard help.&lt;BR /&gt;I've added the error handling.....&lt;BR /&gt;So the problem is that nothing happens - the button does not work but neither are there any exceptions raised...&lt;BR /&gt;So what am I doing wrong? The add-in toolbar appears in the project, the button is enabled but no exceptions appear in the python window and I have no indication the code is executing.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import pythonaddins

class ButtonClass11(object):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for test_addin.button (Button)"""
&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.enabled = True
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.checked = False
try:
# Implementation of OnClick method of Button's class
&amp;nbsp;&amp;nbsp;&amp;nbsp; def onClick(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Get the current map document and the first data frame.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument('current')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Call the zoomToSelectedFeatures() method of the data frame class
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.zoomToSelectedFeatures()
&amp;nbsp;&amp;nbsp;&amp;nbsp; pass
except Exception, e:
&amp;nbsp;&amp;nbsp;&amp;nbsp; traceback.print_exc()&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Maybe a dumb question, but do you have any features selected when you click the button?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can also put a print statement before and after the line you expect to 'do stuff'.&amp;nbsp; In the code above, you can test the zoomToSelectedFeatures method like so,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
print "...attempting to run zoomToSelected"
# Call the zoomToSelectedFeatures() method of the data frame class
df.zoomToSelectedFeatures()
print "...finished running zoomToSelected"
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This will output the two statements in the Python window when you click the add-in button.&amp;nbsp; Just a quick and dirty way to debug.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:37:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/raising-exceptions-in-a-python-thread/m-p/256094#M19693</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-11T12:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to Raise Statements/Handle Errors and Exceptions in a Python Addin?</title>
      <link>https://community.esri.com/t5/python-questions/raising-exceptions-in-a-python-thread/m-p/256095#M19694</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Indentation error. Putting the try: statement at that indent level implicitly takes you out of the class definition and just defines an onClick function not bound to anything. Make it look like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
import pythonaddins
import traceback

class ButtonClass11(object):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for test_addin.button (Button)"""
&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.enabled = True
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.checked = False
&amp;nbsp;&amp;nbsp;&amp;nbsp; def onClick(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Get the current map document and the first data frame.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument('current')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Call the zoomToSelectedFeatures() method of the data frame class
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.zoomToSelectedFeatures()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; except Exception as e:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; traceback.print_exc()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:38:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/raising-exceptions-in-a-python-thread/m-p/256095#M19694</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2021-12-11T12:38:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to Raise Statements/Handle Errors and Exceptions in a Python Addin?</title>
      <link>https://community.esri.com/t5/python-questions/raising-exceptions-in-a-python-thread/m-p/256096#M19695</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks!;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Now thats a lesson in indentation I hopefully won't forget..&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 May 2013 06:52:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/raising-exceptions-in-a-python-thread/m-p/256096#M19695</guid>
      <dc:creator>ColinConstance</dc:creator>
      <dc:date>2013-05-27T06:52:04Z</dc:date>
    </item>
  </channel>
</rss>

