Re: [NOVICE] error handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Apr 13, 2005, at 1:46 AM, Cima wrote:

im working with php 4 and postgresql 8 and i would like to know how to
handle certain errors generated. in postgresql, i've written a stored
function that selects a record from a table and in case no record is found i
'raise an exception'. fine, now in my php script i call that the stored
function which works properly when there is a record but when the record
doesnt exist, i would like to be able to place my own error message and not
e.g 'fatal error, .....'. how do i capture(in php) the exception i raised
in postgres so that i know the record doesnt exist?


You don't say what php library you are using, but perhaps this is what you need:

http://www.php.net/manual/en/function.pg-result-error.php

The only problem with using raise exception for this is that I don't think there is a way for you to assign an error code so you end up parsing a string. This is bad if you want to work in multiple languages. If PostgreSQL is going to generate an error anyway, you might want to let it do that since it should return an error code. See also

http://www.php.net/manual/en/function.pg-result-error-field.php


John DeSoi, Ph.D. http://pgedit.com/ Power Tools for PostgreSQL

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux