Skip to content

Commit

Permalink
remove throw method from Mojo::Exception
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 26, 2016
1 parent 0405c04 commit df394cd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,5 +1,6 @@

6.49 2016-02-26
- Removed throw method from Mojo::Exception.
- Added inspect method to Mojo::Exception.
- Improved check_box and radio_button helpers with support for "on" default
values.
Expand Down
13 changes: 1 addition & 12 deletions lib/Mojo/Exception.pm
Expand Up @@ -32,8 +32,6 @@ sub inspect {

sub new { @_ > 1 ? shift->SUPER::new(message => shift) : shift->SUPER::new }

sub throw { die shift->new(shift)->trace(2)->inspect }

sub to_string {
my $self = shift;

Expand Down Expand Up @@ -98,7 +96,7 @@ Mojo::Exception - Exceptions with context
use Mojo::Exception;
# Throw exception and show stack trace
eval { Mojo::Exception->throw('Something went wrong!') };
eval { die Mojo::Exception->new('Something went wrong!') };
say "$_->[1]:$_->[2]" for @{$@->frames};
# Customize exception
Expand Down Expand Up @@ -182,15 +180,6 @@ L</"lines_before">, L</"line"> and L</"lines_after"> with context information.
Construct a new L<Mojo::Exception> object and assign L</"message"> if necessary.
=head2 throw
Mojo::Exception->throw('Something went wrong!');
Throw exception from the current execution context.
# Longer version
die Mojo::Exception->new('Something went wrong!')->trace->inspect;
=head2 to_string
my $str = $e->to_string;
Expand Down
5 changes: 3 additions & 2 deletions lib/Mojolicious.pm
Expand Up @@ -185,8 +185,9 @@ sub startup { }

sub _exception {
my ($next, $c) = @_;
local $SIG{__DIE__}
= sub { ref $_[0] ? CORE::die $_[0] : Mojo::Exception->throw(@_) };
local $SIG{__DIE__} = sub {
CORE::die ref $_[0] ? $_[0] : Mojo::Exception->new(@_)->trace->inspect;
};
$c->helpers->reply->exception($@) unless eval { $next->(); 1 };
}

Expand Down
5 changes: 3 additions & 2 deletions t/mojo/exception.t
Expand Up @@ -16,7 +16,7 @@ eval {

# test

my $wrapper = sub { Mojo::Exception->throw('Works!') };
my $wrapper = sub { die Mojo::Exception->new('Works!')->trace->inspect };
$wrapper->();

# test
Expand All @@ -36,7 +36,8 @@ is $e->lines_before->[3][0], 18, 'right number';
ok !$e->lines_before->[3][1], 'empty line';
is $e->lines_before->[4][0], 19, 'right number';
is $e->lines_before->[4][1],
" my \$wrapper = sub { Mojo::Exception->throw('Works!') };", 'right line';
" my \$wrapper = sub { die Mojo::Exception->new('Works!')->trace->inspect };",
'right line';
is $e->line->[0], 20, 'right number';
is $e->line->[1], " \$wrapper->();", 'right line';
is $e->lines_after->[0][0], 21, 'right number';
Expand Down

0 comments on commit df394cd

Please sign in to comment.