<?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 Getting error messages for python scripts run in .NET application in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/getting-error-messages-for-python-scripts-run-in/m-p/525038#M14159</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I feel like I'm missing something really obvious, but I can't figure this out. I use ArcObjects to call out to a python script using gp.execute(). When that python script encounters an error, the c# script will stop executing, leaving me no way to get error messages from the python script because anything like gp.GetMessage(ref sev) has to come after the python script call, so it's never hit when the script is erroneous. How do you get your error messages??&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN class="" style="color: slategray;"&gt;//junk here&lt;/SPAN&gt;
gp&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #d74444;"&gt;Execute&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #669900;"&gt;"myscript"&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;,&lt;/SPAN&gt; parameters&lt;SPAN class="" style="color: #999999;"&gt;,&lt;/SPAN&gt; &lt;SPAN class="" style="color: #0077aa;"&gt;null&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;;&lt;/SPAN&gt; &lt;SPAN class="" style="color: slategray;"&gt;//error occurs here&lt;/SPAN&gt;
gp&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #d74444;"&gt;GetMessages&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #0077aa;"&gt;ref&lt;/SPAN&gt; sev&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;;&lt;/SPAN&gt; &lt;SPAN class="" style="color: slategray;"&gt;//cannot actually get these messages because c# script stops executing&lt;/SPAN&gt;
&lt;SPAN class="" style="border-right: 1px solid #999999; padding-top: 1em;"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;What about try/catch blocks?&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN class="" style="color: #0077aa;"&gt;try&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;{&lt;/SPAN&gt;
&lt;SPAN class="" style="color: slategray;"&gt;//junk here&lt;/SPAN&gt;
gp&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #d74444;"&gt;Execute&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;"my script&lt;SPAN class="" style="color: #999999;"&gt;,&lt;/SPAN&gt; parameters&lt;SPAN class="" style="color: #999999;"&gt;,&lt;/SPAN&gt; &lt;SPAN class="" style="color: #0077aa;"&gt;null&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt; &lt;SPAN class="" style="color: slategray;"&gt;//error occurs&lt;/SPAN&gt;
&lt;SPAN class="" style="color: #999999;"&gt;}&lt;/SPAN&gt;
&lt;SPAN class="" style="color: #0077aa;"&gt;catch&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;{&lt;/SPAN&gt;
gp&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #d74444;"&gt;GetMessages&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #0077aa;"&gt;ref&lt;/SPAN&gt; sev&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt; &lt;SPAN class="" style="color: slategray;"&gt;//can't reference gp object here because it is not in scope&lt;/SPAN&gt;
&lt;SPAN class="" style="color: #999999;"&gt;}&lt;/SPAN&gt;&lt;SPAN class="" style="border-right: 1px solid #999999; padding-top: 1em;"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 22:53:26 GMT</pubDate>
    <dc:creator>MKF62</dc:creator>
    <dc:date>2021-12-11T22:53:26Z</dc:date>
    <item>
      <title>Getting error messages for python scripts run in .NET application</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/getting-error-messages-for-python-scripts-run-in/m-p/525038#M14159</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I feel like I'm missing something really obvious, but I can't figure this out. I use ArcObjects to call out to a python script using gp.execute(). When that python script encounters an error, the c# script will stop executing, leaving me no way to get error messages from the python script because anything like gp.GetMessage(ref sev) has to come after the python script call, so it's never hit when the script is erroneous. How do you get your error messages??&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN class="" style="color: slategray;"&gt;//junk here&lt;/SPAN&gt;
gp&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #d74444;"&gt;Execute&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #669900;"&gt;"myscript"&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;,&lt;/SPAN&gt; parameters&lt;SPAN class="" style="color: #999999;"&gt;,&lt;/SPAN&gt; &lt;SPAN class="" style="color: #0077aa;"&gt;null&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;;&lt;/SPAN&gt; &lt;SPAN class="" style="color: slategray;"&gt;//error occurs here&lt;/SPAN&gt;
gp&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #d74444;"&gt;GetMessages&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #0077aa;"&gt;ref&lt;/SPAN&gt; sev&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;;&lt;/SPAN&gt; &lt;SPAN class="" style="color: slategray;"&gt;//cannot actually get these messages because c# script stops executing&lt;/SPAN&gt;
&lt;SPAN class="" style="border-right: 1px solid #999999; padding-top: 1em;"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;What about try/catch blocks?&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN class="" style="color: #0077aa;"&gt;try&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;{&lt;/SPAN&gt;
&lt;SPAN class="" style="color: slategray;"&gt;//junk here&lt;/SPAN&gt;
gp&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #d74444;"&gt;Execute&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;"my script&lt;SPAN class="" style="color: #999999;"&gt;,&lt;/SPAN&gt; parameters&lt;SPAN class="" style="color: #999999;"&gt;,&lt;/SPAN&gt; &lt;SPAN class="" style="color: #0077aa;"&gt;null&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt; &lt;SPAN class="" style="color: slategray;"&gt;//error occurs&lt;/SPAN&gt;
&lt;SPAN class="" style="color: #999999;"&gt;}&lt;/SPAN&gt;
&lt;SPAN class="" style="color: #0077aa;"&gt;catch&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;{&lt;/SPAN&gt;
gp&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #d74444;"&gt;GetMessages&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #0077aa;"&gt;ref&lt;/SPAN&gt; sev&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt; &lt;SPAN class="" style="color: slategray;"&gt;//can't reference gp object here because it is not in scope&lt;/SPAN&gt;
&lt;SPAN class="" style="color: #999999;"&gt;}&lt;/SPAN&gt;&lt;SPAN class="" style="border-right: 1px solid #999999; padding-top: 1em;"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:53:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/getting-error-messages-for-python-scripts-run-in/m-p/525038#M14159</guid>
      <dc:creator>MKF62</dc:creator>
      <dc:date>2021-12-11T22:53:26Z</dc:date>
    </item>
    <item>
      <title>Re: Getting error messages for python scripts run in .NET application</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/getting-error-messages-for-python-scripts-run-in/m-p/525039#M14160</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The solution is to move everything out of the "try" block except for the execute statement. That way the gp object is moved into the local scope where it can be accessed by the "catch" block.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;IGeoProcessor2 gp &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;new&lt;/SPAN&gt; &lt;SPAN class="token class-name"&gt;GeoProcessorClass&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
gp&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;AddToolbox&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"myPathToToolboxPopulatePatches"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
IVariantArray parameters &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;new&lt;/SPAN&gt; &lt;SPAN class="token class-name"&gt;VarArrayClass&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
parameters&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;Add&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;shapefile&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;try&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; gp&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;Execute&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"PopulatePatches"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;parameters&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;null&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;catch&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;object&lt;/SPAN&gt; erSeverity &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;string&lt;/SPAN&gt; erMessages &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; gp&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;GetMessages&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="keyword token"&gt;ref&lt;/SPAN&gt; erSeverity&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; ViewBag&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Messages &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; erMessages&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;View&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;//more code if tool executes properly&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;View&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:53:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/getting-error-messages-for-python-scripts-run-in/m-p/525039#M14160</guid>
      <dc:creator>MKF62</dc:creator>
      <dc:date>2021-12-11T22:53:28Z</dc:date>
    </item>
  </channel>
</rss>

