Thread: Error handling in pltcl
Hi,
Can any one tell me how to handle error in PL/TCL language.
On Error/Exception,
In the exception block I want to call a FUNCTION (written in PL/pgSQL).
Thanks
Dinesh Pandey
On Mon, Apr 18, 2005 at 09:20:37AM +0530, Dinesh Pandey wrote: > > Can any one tell me how to handle error in PL/TCL language. What kind of error? Have you tried using catch? > On Error/Exception, > In the exception block I want to call a FUNCTION (written in PL/pgSQL). You could use spi_exec to SELECT the function. If you still have trouble, then please post a simple example that shows what you're trying to do. BTW, pgsql-sql probably isn't the best place to ask PL/Tcl questions since its description is "Discussion for users on SQL related matters." pgsql-general or pgsql-interfaces might be more appropriate. -- Michael Fuhr http://www.fuhr.org/~mfuhr/
I have attached below an e-mail program. I want to log messages into a table from a function written in 'plpgsql' whenever any exception occurs (like unable to connect/invalid email etc..) Pls update the code attached below Thanks Dinesh Pandey ======================== CREATE OR REPLACE FUNCTION PGMAIL(text, text, text, text, text, text) RETURNS INT4 AS 'set mailfrom $1set mailto $2set mailcc $3set mailserver $4set mailsubject $5set mailmessage$6 # Mail Server set myHost $mailserver # Mail Server SMTP Port set myPort 25set mySock [socket $myHost $myPort] # Mail To Addressset toemailaddress_start [string first "<" $mailto]if {$toemailaddress_start != -1} { set toemailaddress_finish[string first ">" $mailto] set toemailaddress_start [expr $toemailaddress_start + 1] set toemailaddress_finish[expr $toemailaddress_finish - 1] set toemailaddress [string range $mailto $toemailaddress_start $toemailaddress_finish]} else { set toemailaddress $mailto} # Mail Cc Addressset ccemailaddress_start [string first "<" $mailcc]if {$ccemailaddress_start != -1} { set ccemailaddress_finish[string first ">" $mailcc] set ccemailaddress_start [expr $ccemailaddress_start + 1] set ccemailaddress_finish[expr $ccemailaddress_finish - 1] set ccemailaddress [string range $mailcc $toemailaddress_start $ccemailaddress_finish]} else { set ccemailaddress $mailcc} # Mail From Address set fromemailaddress_start [string first "<" $mailfrom]if {$fromemailaddress_start != -1} { setfromemailaddress_finish [string first ">" $mailfrom] set fromemailaddress_start [expr $fromemailaddress_start + 1] set fromemailaddress_finish [expr $fromemailaddress_finish - 1] set fromemailaddress [string range $mailfrom $fromemailaddress_start $fromemailaddress_finish]} else { set fromemailaddress $mailfrom}fileevent $mySock writable [listsvcHandler $mySock] fconfigure $mySock -buffering none puts $mySock "helo $mailserver" gets $mySockname puts $mySock "mail from: $fromemailaddress" gets $mySock name puts $mySock "rcpt to: $toemailaddress" gets $mySock name puts $mySock "rcpt cc: $ccemailaddress" gets $mySock name puts $mySock"data" gets $mySock name puts $mySock "To: $mailto" puts $mySock "Cc: $mailcc" puts $mySock "From:$mailfrom" puts $mySock "Subject: $mailsubject" puts $mySock "" puts $mySock "$mailmessage" puts$mySock "." gets $mySock nameclose $mySockreturn 1' #Exception handling LANGUAGE 'pltclu'; ========================