cvsuser 02/02/28 21:09:16
Modified: P5EEx/Blue/P5EEx/Blue/Widget HTML.pm
Log:
catch exceptions when trying to display() an HTML Widget
Revision Changes Path
1.3 +40 -3 p5ee/P5EEx/Blue/P5EEx/Blue/Widget/HTML.pm
Index: HTML.pm
===================================================================
RCS file: /cvs/public/p5ee/P5EEx/Blue/P5EEx/Blue/Widget/HTML.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -w -r1.2 -r1.3
--- HTML.pm 8 Feb 2002 20:43:36 -0000 1.2
+++ HTML.pm 1 Mar 2002 05:09:16 -0000 1.3
@@ -1,10 +1,10 @@
######################################################################
-## $Id: HTML.pm,v 1.2 2002/02/08 20:43:36 spadkins Exp $
+## $Id: HTML.pm,v 1.3 2002/03/01 05:09:16 spadkins Exp $
######################################################################
package P5EEx::Blue::Widget::HTML;
-$VERSION = do { my @r=(q$Revision: 1.2 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
+$VERSION = do { my @r=(q$Revision: 1.3 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
use P5EEx::Blue::Widget;
@ISA = ( "P5EEx::Blue::Widget" );
@@ -122,13 +122,50 @@
# They can only render themselves as HTML.
# If the Context decides this should be sent to the browser, that is
# its choice and not an action of the widget itself.
+# However, this is a convenient place to put protections agains exceptions.
+# Perhaps it should be called something else, but it definitely has a role.
+
sub display {
my $self = shift;
+ my ($html);
$self->{context}->dbgprint("P5EEx::Blue::Widget::HTML(", $self->{name},
")->display()")
if ($P5EEx::Blue::Context::DEBUG >= 1 && $self->{context}->dbg(ref($self)));
- $self->html();
+ eval {
+ $html = $self->html();
+ };
+ if ($@) {
+ my ($name, $msg);
+ if (ref($@) eq "") { # i.e. a string thrown with "die"
+ $msg = $@;
+ }
+ elsif ($@->isa("P5EEx::Blue::Exception")) {
+ $msg = $@->error . "\n" . $@->trace->as_string . "\n";
+ }
+ else {
+ $@->rethrow();
+ }
+ $msg =~ s{&}{&}gso;
+ $msg =~ s{<}{<}gso;
+ $msg =~ s{>}{>}gso;
+ $msg =~ s{\"}{"}gso;
+ $msg =~ s{\n}{<br>\n}gso;
+ $name = $self->{name};
+ $html = <<EOF;
+<table border="1" cellspacing="0">
+<tr><td bgcolor="#aaaaaa">
+<b>Widget Display Error: $name</b><br>
+</td></tr>
+<tr><td bgcolor="#ffaaaa">
+<font size="-1" face="sans-serif">
+$msg
+</font>
+</td></tr>
+</table>
+EOF
+ }
+ return $html;
}
1;