<div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">is there any standard way how to catch Exceptions from Postgis functions?<br>For Example:<br>
SELECT ST_Split(polygon_geom, polygon_geom)<br>result in general PostgreSQL InternalError exception with CODE XX000.<br></blockquote><div><br></div><div>My preferred way is to write a custom wrapper function in PL/pgSQL for error handling with PostGIS functions. </div><div><br></div><div>Random examples:</div><div><br></div><div><a href="https://github.com/kiselev-dv/osm-addresses-pgsql/blob/master/St_CancaveHull_Safe.sql">https://github.com/kiselev-dv/osm-addresses-pgsql/blob/master/St_CancaveHull_Safe.sql</a><br></div><div>~ " ...   <font face="monospace"><i>EXCEPTION WHEN SQLSTATE 'XX000' THEN return null; </i></font> " <br></div><div><br></div><div>or </div><div><a href="https://github.com/gojuno/lostgis/blob/master/sql/functions/ST_Safe_Intersection.sql">https://github.com/gojuno/lostgis/blob/master/sql/functions/ST_Safe_Intersection.sql</a><br></div><div><a href="https://github.com/gojuno/lostgis/blob/master/sql/functions/ST_Safe_Difference.sql">https://github.com/gojuno/lostgis/blob/master/sql/functions/ST_Safe_Difference.sql</a><br></div><div><a href="https://github.com/gojuno/lostgis/blob/master/sql/functions/ST_Safe_Repair.sql">https://github.com/gojuno/lostgis/blob/master/sql/functions/ST_Safe_Repair.sql</a><br></div><div><br></div><div>or </div><div><a href="https://github.com/AfESG/AED-Platform/blob/master/script/etl/safe_isect.sql">https://github.com/AfESG/AED-Platform/blob/master/script/etl/safe_isect.sql</a><br></div><div><br></div><div><br></div><div>>  I mean how to catch from programing language code. PHP, Python, ...<br></div><div><br></div><div>Maybe with the <a href="https://www.psycopg.org/docs/errors.html">https://www.psycopg.org/docs/errors.html</a>  ?</div><div><i><font face="monospace"> except psycopg2.InternalError as exc:<br></font></i></div><div><i><font face="monospace">        if exc.pgcode == "XX000":</font></i><br></div><div><br></div><div>Regards,</div><div> Imre</div><div><br></div></div></div>