Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
Thread: Python error handling
07-29-2008, 06:30 PM #1
- Join Date
- Dec 2004
- Thanked 0 Times in 0 Posts
Python error handling
How does one achieve this...
Say I've got a line that reads...
plpy.execute("some sql command that might throw an error");
How do I handle that error?
create or replace function prepare(tbl varchar, edgetbl varchar) returns integer as $$ plpy.info ("Roads Table: " + tbl) plpy.info ("Edges Table: " + edgetbl) createstr = "CREATE TABLE " + edgetbl + " ( gid int8, n_gid int8, dist int8, foreign key (gid) references roads (gid), foreign key (n_gid) references roads (gid), primary key (gid,n_gid) )" try: plpy.execute(createstr) except: plpy.info ("The table " + edgetbl + " was already created") plpy.info ("Moving On") $$ language plpythonu;
INFO: ('Roads Table: roads',)
INFO: ('Edges Table: edges',)
WARNING: plpython: in function prepare:
DETAIL: <class 'plpy.SPIError'>: Unknown error in PLy_spi_execute_query
INFO: ('The table edges was already created',)
INFO: ('Moving On',)
ERROR: relation "edges" already exists
CONTEXT: SQL statement "CREATE TABLE edges ( gid int8, n_gid int8, dist int8, foreign key (gid) references roads (gid), foreign key (n_gid) references roads (gid), primary key (gid,n_gid) )"
However... it does not execute the last line... so the catch is apparently not working.I'm gonna find a way to download the internet if its the last thing I do...
Prepare to bow down to me (or my grave) and call me almighty when the algorithm is finished