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

exception handling

 
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 -> Smarty 3
View previous topic :: View next topic  
Author Message
yankee
Smarty Rookie


Joined: 02 Mar 2009
Posts: 31

PostPosted: Fri Jul 03, 2009 9:09 am    Post subject: exception handling Reply with quote

Hi @ll,

my php application had a very weird problem that I just had no idea where it came from: Exceptions where not displayed in the way I wanted them to. But with certain exceptions it worked perfectly fine.
First I thought my exception handler was not fired, but the output did not look like php's default output nor like the modified output created by XDebug.
Eventually I changed the script so I could step through it line by line using eclipse pdt and XDebug. I quickly stepped through the code up to the point where the exception that was not displayed correctly was thrown. Suddenly I ended up in a class called SmartyException and was stuned. Especially since this exception had nothing to do in the least with smarty.

But yes... That explained everything. All the exceptions that ware handled by my exception handler were thrown before instantiating the Smarty class. Smarty overrides my exception handler.
Why are you doing this?
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Fri Jul 03, 2009 2:18 pm    Post subject: Reply with quote

By default Smarty handles exceptions during template processing, for those that don't gracefully handle them themselves. If you don't want Smarty handling any exceptions, set

Code:
$smarty->exception_handler = null;


There has been a debate about the default exception handling in the dev mailing list, and we're open to comments/suggestions.
Back to top
View user's profile Send private message Visit poster's website
yankee
Smarty Rookie


Joined: 02 Mar 2009
Posts: 31

PostPosted: Fri Jul 03, 2009 2:23 pm    Post subject: Reply with quote

mohrt wrote:
By default Smarty handles exceptions during template processing, for those that don't gracefully handle them themselves. If you don't want Smarty handling any exceptions, set

Code:
$smarty->exception_handler = null;

What's more graceful about smarty's exception handler? The minimum you could do is print out an information that the message has been caught by smarty's exception handler. That could save one a lot of stepping through code.

Anyway... Since this:
Code:
if (!empty($this->exception_handler))
            set_exception_handler($this->exception_handler);

is in smarty's constructor, I guess I have to do this:
Code:
$smarty->exception_handler = null;

BEFORE calling the constructor which is very hard to do.
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Fri Jul 03, 2009 2:38 pm    Post subject: Reply with quote

Yes we have discussed just yanking the exception handling. The problem is that if Smarty doesn't handle exceptions and the application using Smarty doesn't either (as most upgrading Smarty 2 -> Smarty 3 would have), then PHP complains about uncaught exceptions and we get lots of support questions about the exception warnings. So we thought to handle them by default, and offer a way to turn them off.

I see your point about the constructor. You would have to extend the Smarty class and set that property to null. Maybe we need to supply a way to turn them off in the main class, such as a param to the constructor. Or, remove exception handling altogether and deal with complaints separately.
Back to top
View user's profile Send private message Visit poster's website
yankee
Smarty Rookie


Joined: 02 Mar 2009
Posts: 31

PostPosted: Fri Jul 03, 2009 2:49 pm    Post subject: Reply with quote

mohrt wrote:
Yes we have discussed just yanking the exception handling. The problem is that if Smarty doesn't handle exceptions and the application using Smarty doesn't either (as most upgrading Smarty 2 -> Smarty 3 would have), then PHP complains about uncaught exceptions and we get lots of support questions about the exception warnings.

Well yes, but you will geht support questions one way or another. This way you will even get support questions concerning exceptions that don't even have to do anything with smarty (this one here is the first one...).
It's not like using a different exception handler will change anything about the error that caused it after all.
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Fri Jul 03, 2009 2:49 pm    Post subject: Reply with quote

Please update your SVN, and then do the following:

Code:
define('SMARTY_EXCEPTION_HANDLER',0);
include('Smarty.class.php');
$smarty = new Smarty();
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


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

PostPosted: Fri Jul 03, 2009 2:51 pm    Post subject: Reply with quote

yankee wrote:
mohrt wrote:
Yes we have discussed just yanking the exception handling. The problem is that if Smarty doesn't handle exceptions and the application using Smarty doesn't either (as most upgrading Smarty 2 -> Smarty 3 would have), then PHP complains about uncaught exceptions and we get lots of support questions about the exception warnings.

Well yes, but you will geht support questions one way or another. This way you will even get support questions concerning exceptions that don't even have to do anything with smarty (this one here is the first one...).
It's not like using a different exception handler will change anything about the error that caused it after all.


Noted. We may very well yank it. Please try the above and give your feedback.
Back to top
View user's profile Send private message Visit poster's website
yankee
Smarty Rookie


Joined: 02 Mar 2009
Posts: 31

PostPosted: Fri Jul 03, 2009 2:51 pm    Post subject: Reply with quote

mohrt wrote:
Please update your SVN, and then do the following:

Code:
define('SMARTY_EXCEPTION_HANDLER',0);
include('Smarty.class.php');
$smarty = new Smarty();

Well, that'll do for now. But still I'd like to encourage you to rethink exception handling.
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Fri Jul 03, 2009 2:55 pm    Post subject: Reply with quote

One other thing to note, Smarty sets its own exception handler during the entire existence of the Smarty object. Maybe it should only set the exception handler during the execution of display() or fetch() calls to avoid the non-smarty exception issues.
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


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

PostPosted: Fri Jul 03, 2009 3:01 pm    Post subject: Reply with quote

I will give you an example using a tpl function that is not defined:

With Smarty exception handler:

Code:
Code: 0<br />Error: Syntax Error in template &quot;./templates/index.tpl&quot;  on line 3 &quot;DONE&quot; unknown tag &quot;foo&quot;<br />File: /home/mohrt/www/php/smarty-branches/Smarty3Alpha/distribution/libs/sysplugins/internal.templatecompilerbase.php<br />Line: 265<br />


without an exception handler:

Code:

Fatal error: Uncaught exception 'Exception' with message 'Syntax Error in template "./templates/index.tpl"  on line 3 "DONE" unknown tag "foo"' in /home/mohrt/www/php/smarty-branches/Smarty3Alpha/distribution/libs/sysplugins/internal.templatecompilerbase.php:265
Stack trace:
#0 /home/mohrt/www/php/smarty-branches/Smarty3Alpha/distribution/libs/sysplugins/internal.templatecompilerbase.php(190): Smarty_Internal_TemplateCompilerBase->trigger_template_error('unknown tag "fo...')
#1 /home/mohrt/www/php/smarty-branches/Smarty3Alpha/distribution/libs/sysplugins/internal.templateparser.php(1912): Smarty_Internal_TemplateCompilerBase->compileTag('foo', Array)
#2 /home/mohrt/www/php/smarty-branches/Smarty3Alpha/distribution/libs/sysplugins/internal.templateparser.php(2308): Smarty_Internal_Templateparser->yy_r16()
#3 /home/mohrt/www/php/smarty-branches/Smarty3Alpha/distribution/libs/sysplugins/internal.templateparser.php(2447): Smarty_Internal_Templateparser->yy_reduce(16)
#4 /home/mohrt/www/php/smarty-branches/Smarty3Alpha/distrib in /home/mohrt/www/php/smarty-branches/Smarty3Alpha/distribution/libs/sysplugins/internal.templatecompilerbase.php on line 265


You see where the questions come in "Smarty has Fatal Error" Smile
Back to top
View user's profile Send private message Visit poster's website
yankee
Smarty Rookie


Joined: 02 Mar 2009
Posts: 31

PostPosted: Fri Jul 03, 2009 3:16 pm    Post subject: Reply with quote

mohrt wrote:
You see where the questions come in "Smarty has Fatal Error" Smile

Well... This would most definitly show that the poster did not read the text in the error message since it is all there to see that it is no bug in smarty but in the users code instead.
But yes... You are right. There are plenty of people out there who would not read the f***ing message. I don't like to adapt the design of anything to those people, but I can see your point...
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 -> Smarty 3 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