pg_connect không đưa ra ngoại lệ, vì vậy bạn phải dịch sang ngoại lệ như bên dưới.
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
}
set_error_handler("exception_error_handler");
try {
example@sqldat.com_connect("host=dbhost user=dbuser dbname=db password=dbpass");
} Catch (Exception $e) {
Echo $e->getMessage();
}
Vui lòng tham khảo thêm chi tiết này
https://php.net/manual/en/language.exceptions.php