Easy A
Would you like to react to this message? Create an account in a few clicks or log in to continue.


 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  

Share
 

 Python error handling

View previous topic View next topic Go down 
AuthorMessage
Mystic
Member
Member
Mystic

Posts : 3
Join date : 2011-06-24

Python error handling Empty
PostSubject: Python error handling   Python error handling EmptyWed Jun 29, 2011 5:55 am

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?
I've tried:
Code:

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;

Which gave me the output:
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.
Back to top Go down
 

Python error handling

View previous topic View next topic Back to top 
Page 1 of 1

 Similar topics

-
» javascript values back to python?
» Object Error... Why????
» Error in rails gem installation
» recordset error in loop
» w3c validation - please help correcting the error

Permissions in this forum:You cannot reply to topics in this forum
Easy A :: Python error handling Edit-trash Useless :: Trash-