View previous topic :: View next topic |
Author |
Message |
maka Smarty Rookie
Joined: 15 May 2003 Posts: 21 Location: Maringá-PR BRASIL
|
Posted: Mon May 19, 2003 5:15 am Post subject: how to catch error messages? |
|
|
Hi,
I'm doing a form_mail class to send html email with templates.
My problem is that after fetch the template to a var, if there was a error its going to the var. I want to know if a error occur and catch the message to write other place.
I look at the documentation and don't found how.
thanks,
sorry my english |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed May 21, 2003 2:10 am Post subject: |
|
|
What kind of errors are you trying to catch? Application errors or Smarty errors?
You can try using Smarty::trigger_error() within your custom plugins and then use a custom PHP error handler.
Perhaps you can provide a code snippet that demonstrates your particular situation? |
|
Back to top |
|
maka Smarty Rookie
Joined: 15 May 2003 Posts: 21 Location: Maringá-PR BRASIL
|
Posted: Wed May 21, 2003 11:24 am Post subject: |
|
|
here goes a example:
<?
require_once 'smarty/Smarty.class.php';
$smarty = new Smarty;
// line below give a error if template.tpl doesn´t exist
echo $smarty->fetch('template.tpl');
//I wanted to do something like this, or similar:
if($return = $smarty->fetch('template.tpl')){
echo $return;
}else{
//treatment of error
}
?> |
|
Back to top |
|
maka Smarty Rookie
Joined: 15 May 2003 Posts: 21 Location: Maringá-PR BRASIL
|
Posted: Mon Jun 02, 2003 7:40 pm Post subject: |
|
|
no one's got an answer? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Mon Jun 02, 2003 8:26 pm Post subject: |
|
|
May I suggest you read the PHP Manual Entry for set_error_handler or the link I provided above for a tutorial style example.
This is an issue with understanding how error handling in PHP works--in the end, you have to write the code yourself so understanding how this works is a very good idea.
Good Luck!! |
|
Back to top |
|
maka Smarty Rookie
Joined: 15 May 2003 Posts: 21 Location: Maringá-PR BRASIL
|
Posted: Tue Jun 10, 2003 4:53 am Post subject: |
|
|
thanks boots!
set_error_handler is a cool way to handle errors.
I'm just getting a problem. I usualy do the follow code <?= @$email ?>
If $email is not set, I get no notice, cause I'm using the @ operator.
But using set_error_handler, the @ operator has no effect. Do you know why? For the moment I'm replacing the code to:
<?= isset($email) ? $email : NULL ?>
any better idea? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Jun 10, 2003 2:43 pm Post subject: |
|
|
I think it is possible to test whether an error was supressed with @ or not within the set_error_handler function. I don't remember off the top of my head how to do it though.
Monte |
|
Back to top |
|
maka Smarty Rookie
Joined: 15 May 2003 Posts: 21 Location: Maringá-PR BRASIL
|
Posted: Wed Jun 11, 2003 5:21 am Post subject: |
|
|
hi mohrt!!
this is a part of text from the PHP manual about se_error_handler
It is important to remember that the standard PHP error handler is completely bypassed. error_reporting() settings will have no effect and your error handler will be called regardless - however you are still able to read the current value of error_reporting and act appropriately. Of particular note is that this value will be 0 if the statement that caused the error was prepended by the @ error-control operator.
I think it's telling what you wanted do say. Special the bold part. But I didn't understand whitch value will be 0 if use @.
it's refresh your mind? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Jun 11, 2003 5:39 am Post subject: |
|
|
I haven't tested, but this may work:
if (get_cfg_var('error_reporting') == 0) {
// silent, eh?
}
See Also:
get_cfg_var
The other thing to check out is the track_errors feature which, if enabled, should still store the error message in $php_errormsg even when using @.
See Also:
Error Control Operators
I am looking forward to try/catch support in PHP5 |
|
Back to top |
|
maka Smarty Rookie
Joined: 15 May 2003 Posts: 21 Location: Maringá-PR BRASIL
|
Posted: Wed Jun 11, 2003 5:41 am Post subject: |
|
|
mohrt, ignore the above post.
error_reporting will be 0 if use @, so in my handler i use:
if(ini_get('error_reporting') == 0) return NULL
so the handler stop ignoring the rest of code
thanks folks!!! |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Jun 11, 2003 5:44 am Post subject: |
|
|
@maka: I think that if you use ini_get you are only getting the default value for error_reporting that is assigned in the php.ini. |
|
Back to top |
|
maka Smarty Rookie
Joined: 15 May 2003 Posts: 21 Location: Maringá-PR BRASIL
|
Posted: Wed Jun 11, 2003 5:51 am Post subject: |
|
|
thanks boots too,
Witch is the difference between get_cfg_var and ini_get?
the only think I know is that with ini_get works, but with get_cfg_var doesn't. Seens that get_cfg_var takes the initial config and ini_get takes the imediate. look this test:
<?
echo get_cfg_var('error_reporting');
echo '<br>';
echo ini_get('error_reporting');
echo '<br>';
ini_set('error_reporting',E_WARNING);
echo get_cfg_var('error_reporting');
echo '<br>';
echo ini_get('error_reporting');
?>
thanks, and sorry my poor English |
|
Back to top |
|
maka Smarty Rookie
Joined: 15 May 2003 Posts: 21 Location: Maringá-PR BRASIL
|
Posted: Wed Jun 11, 2003 6:15 am Post subject: |
|
|
boots,
where can I read about the PHP 5 new features? and when its coming out? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Jun 11, 2003 6:43 am Post subject: |
|
|
Hi maka:
Sorry about that I should have checked my code--you were right and I had it backwards. The ini_get is the function to use and actually, get_cfg_var doesn't do very many nice things.
There are several articles on PHP5 cropping up:
* Introduction to PHP5 @ PHPBuilder.com.
* Introduction to PHP5 - slides from talk by Sterling Hughes
* PHP: Into the Future @ Zend.com
If I'm not mistaken, PHP5 will be done when it is done I believe that the core developers are preparing for an imminent beta release since the target they were working for was to release a beta in the first half of this year. My guess (and do I mean total guess) is 6 months to a year before the first full release of PHP5, assuming that a beta is released very soon.
Cheers. |
|
Back to top |
|
|