From 4836936fe5057b0857394164c67127d9d5990e23 Mon Sep 17 00:00:00 2001 From: Dmitry Karasik Date: Mon, 2 Oct 2023 14:27:03 +0200 Subject: [PATCH] Prima::Dialog::execute can handle exceptions the same way as Prima::run does --- Prima/Application.pm | 8 ++++---- Prima/Classes.pm | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Prima/Application.pm b/Prima/Application.pm index a3a0c5bf6..92ebf2b8d 100644 --- a/Prima/Application.pm +++ b/Prima/Application.pm @@ -204,7 +204,6 @@ and if you want to treat all warnings as potentially fatal, like this: }); }; - See also: L, L =back @@ -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 call; if there -is a call to f ex C or a manual event loop run with -C, the dialog will not be shown. One needs to explicitly call C<< +Note that the exception is only handled inside the C and +C calls; if there is a call to f ex +C or a manual event loop run with C, 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. diff --git a/Prima/Classes.pm b/Prima/Classes.pm index cbe28ee52..0af1c2589 100644 --- a/Prima/Classes.pm +++ b/Prima/Classes.pm @@ -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);