Re: Exceptions and builtin functions in PHP5

From: Date: Fri, 09 Apr 2004 09:43:59 +0000
Subject: Re: Exceptions and builtin functions in PHP5
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-9022@lists.php.net to get a copy of this message
Hello Tumurbaatar, iam curios, why would you want to change the exceptions parameters $file and $line? They are both available through the backtrace at the second element. Try the following: [...] catch (Exception $e) { $trace = $e->getTrace(); var_dump($trace[1]); } That outputs: array(3) { ["file"]=> string(36) "/usr/src/php-cvs/tests/lang/038.phpt" ["line"]=> int(26) ["function"]=> string(10) "pg_connect" } regards marcus Friday, April 9, 2004, 7:42:32 AM, you wrote: >> >> Perhaps this could be done in userland by throwing an exception in a >> user error_handler... did not test it though... >> > It seems that works! At least for E_WARNING: > class MyException extends Exception > { > function __construct($errno, $errstr, $errfile, $errline) > { > parent::__construct($errstr, $errno); > $this->file = $errfile; > $this->line = $errline; > } > } > function Error2Exception($errno, $errstr, $errfile, $errline) > { > throw new MyException($errno, $errstr, $errfile, $errline); > } > $err_msg = 'no exception'; > set_error_handler('Error2Exception'); > try > { > $con = pg_connect('host=localhost dbname=test'); > } > catch (Exception $e) > { > $err_msg = sprintf('%x - %s', $e->getCode(), $e->getMessage()); > } -- Best regards, Marcus mailto:helly@php.net

« previous php.internals (#9022) next »