Skip to content

Commit

Permalink
Prima::Dialog::execute can handle exceptions the same way as Prima::r…
Browse files Browse the repository at this point in the history
…un does
  • Loading branch information
dk committed Oct 2, 2023
1 parent 7aacf07 commit 4836936
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Prima/Application.pm
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ and if you want to treat all warnings as potentially fatal, like this:
});
};
See also: L<Die>, L<Prima::MsgBox/signal_dialog>
=back
Expand Down Expand Up @@ -232,9 +231,10 @@ allowing the user to choose the course of action -- to stop, to continue, etc.
Is 0 by default.
Note that the exception is only handled inside the C<Prima::run> call; if there
is a call to f ex C<Prima::Dialog::execute> or a manual event loop run with
C<yield>, the dialog will not be shown. One needs to explicitly call C<<
Note that the exception is only handled inside the C<Prima::run> and
C<Prima::Dialog::execute> calls; if there is a call to f ex
C<Prima::Window::execute> or a manual event loop run with C<yield>, the signal
dialog will not be shown. One needs to explicitly call C<<
$::application->notify(Die => $@) >> and check the notification result to
decide whether to propagate the exception or not.
Expand Down
21 changes: 21 additions & 0 deletions Prima/Classes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2089,6 +2089,27 @@ sub profile_default
return $def;
}

sub execute
{
my ( $self, @p ) = @_;

my ($result, $stack, $got_exception) = (mb::Cancel, '', 0);
local $SIG{__DIE__} = sub {
$got_exception = 1;
$stack //= Carp::longmess();
die @_;
};
eval {
$result = $self->SUPER::execute(@p);
$got_exception = 0;
};
if ( $got_exception && $::application->alive ) {
my $error = $@;
die $error if $::application->notify('Die', "$@", $stack);
}
return $result;
}

package Prima::MainWindow;
use vars qw(@ISA);
@ISA = qw(Prima::Window);
Expand Down

0 comments on commit 4836936

Please sign in to comment.