Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

how to catch error messages?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
maka
Smarty Rookie


Joined: 15 May 2003
Posts: 21
Location: Maringá-PR BRASIL

PostPosted: Mon May 19, 2003 5:15 am    Post subject: how to catch error messages? Reply with quote

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, Cool

sorry my english Embarassed
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed May 21, 2003 2:10 am    Post subject: Reply with quote

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
View user's profile Send private message
maka
Smarty Rookie


Joined: 15 May 2003
Posts: 21
Location: Maringá-PR BRASIL

PostPosted: Wed May 21, 2003 11:24 am    Post subject: Reply with quote

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
View user's profile Send private message
maka
Smarty Rookie


Joined: 15 May 2003
Posts: 21
Location: Maringá-PR BRASIL

PostPosted: Mon Jun 02, 2003 7:40 pm    Post subject: Reply with quote

no one's got an answer?
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Mon Jun 02, 2003 8:26 pm    Post subject: Reply with quote

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
View user's profile Send private message
maka
Smarty Rookie


Joined: 15 May 2003
Posts: 21
Location: Maringá-PR BRASIL

PostPosted: Tue Jun 10, 2003 4:53 am    Post subject: Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Jun 10, 2003 2:43 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
maka
Smarty Rookie


Joined: 15 May 2003
Posts: 21
Location: Maringá-PR BRASIL

PostPosted: Wed Jun 11, 2003 5:21 am    Post subject: Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Jun 11, 2003 5:39 am    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message
maka
Smarty Rookie


Joined: 15 May 2003
Posts: 21
Location: Maringá-PR BRASIL

PostPosted: Wed Jun 11, 2003 5:41 am    Post subject: Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Jun 11, 2003 5:44 am    Post subject: Reply with quote

@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
View user's profile Send private message
maka
Smarty Rookie


Joined: 15 May 2003
Posts: 21
Location: Maringá-PR BRASIL

PostPosted: Wed Jun 11, 2003 5:51 am    Post subject: Reply with quote

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
View user's profile Send private message
maka
Smarty Rookie


Joined: 15 May 2003
Posts: 21
Location: Maringá-PR BRASIL

PostPosted: Wed Jun 11, 2003 6:15 am    Post subject: Reply with quote

boots,
where can I read about the PHP 5 new features? and when its coming out?
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Jun 11, 2003 6:43 am    Post subject: Reply with quote

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 Smile 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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP