.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Mojo::Exception 3pm" .TH Mojo::Exception 3pm "2019-02-05" "perl v5.28.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Mojo::Exception \- Exceptions with context .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Mojo::Exception; \& \& # Throw exception and show stack trace \& eval { Mojo::Exception\->throw(\*(AqSomething went wrong!\*(Aq) }; \& say "$_\->[1]:$_\->[2]" for @{$@\->frames}; \& \& # Customize exception \& eval { \& my $e = Mojo::Exception\->new(\*(AqDied at test.pl line 3.\*(Aq); \& die $e\->trace(2)\->inspect\->verbose(1); \& }; \& say $@; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Mojo::Exception is a container for exceptions with context information. .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" Mojo::Exception implements the following attributes. .SS "frames" .IX Subsection "frames" .Vb 2 \& my $frames = $e\->frames; \& $e = $e\->frames([$frame1, $frame2]); .Ve .PP Stack trace if available. .PP .Vb 3 \& # Extract information from the last frame \& my ($package, $filename, $line, $subroutine, $hasargs, $wantarray, $evaltext, \& $is_require, $hints, $bitmask, $hinthash) = @{$e\->frames\->[\-1]}; .Ve .SS "line" .IX Subsection "line" .Vb 2 \& my $line = $e\->line; \& $e = $e\->line([3, \*(Aqdie;\*(Aq]); .Ve .PP The line where the exception occurred if available. .SS "lines_after" .IX Subsection "lines_after" .Vb 2 \& my $lines = $e\->lines_after; \& $e = $e\->lines_after([[4, \*(Aqsay $foo;\*(Aq], [5, \*(Aqsay $bar;\*(Aq]]); .Ve .PP Lines after the line where the exception occurred if available. .SS "lines_before" .IX Subsection "lines_before" .Vb 2 \& my $lines = $e\->lines_before; \& $e = $e\->lines_before([[1, \*(Aqmy $foo = 23;\*(Aq], [2, \*(Aqmy $bar = 24;\*(Aq]]); .Ve .PP Lines before the line where the exception occurred if available. .SS "message" .IX Subsection "message" .Vb 2 \& my $msg = $e\->message; \& $e = $e\->message(\*(AqDied at test.pl line 3.\*(Aq); .Ve .PP Exception message, defaults to \f(CW\*(C`Exception!\*(C'\fR. .SS "verbose" .IX Subsection "verbose" .Vb 2 \& my $bool = $e\->verbose; \& $e = $e\->verbose($bool); .Ve .PP Enable context information for \*(L"to_string\*(R". .SH "METHODS" .IX Header "METHODS" Mojo::Exception inherits all methods from Mojo::Base and implements the following new ones. .SS "inspect" .IX Subsection "inspect" .Vb 2 \& $e = $e\->inspect; \& $e = $e\->inspect($source1, $source2); .Ve .PP Inspect \*(L"message\*(R", \*(L"frames\*(R" and optional additional sources to fill \&\*(L"lines_before\*(R", \*(L"line\*(R" and \*(L"lines_after\*(R" with context information. .SS "new" .IX Subsection "new" .Vb 2 \& my $e = Mojo::Exception\->new; \& my $e = Mojo::Exception\->new(\*(AqDied at test.pl line 3.\*(Aq); .Ve .PP Construct a new Mojo::Exception object and assign \*(L"message\*(R" if necessary. .SS "to_string" .IX Subsection "to_string" .Vb 1 \& my $str = $e\->to_string; .Ve .PP Render exception. .PP .Vb 2 \& # Render exception with context \& say $e\->verbose(1)\->to_string; .Ve .SS "throw" .IX Subsection "throw" .Vb 1 \& Mojo::Exception\->throw(\*(AqSomething went wrong!\*(Aq); .Ve .PP Throw exception from the current execution context. .PP .Vb 2 \& # Longer version \& die Mojo::Exception\->new(\*(AqSomething went wrong!\*(Aq)\->trace\->inspect; .Ve .SS "trace" .IX Subsection "trace" .Vb 2 \& $e = $e\->trace; \& $e = $e\->trace($skip); .Ve .PP Generate stack trace and store all \*(L"frames\*(R", defaults to skipping \f(CW1\fR call frame. .PP .Vb 2 \& # Skip 3 call frames \& $e\->trace(3); \& \& # Skip no call frames \& $e\->trace(0); .Ve .SH "OPERATORS" .IX Header "OPERATORS" Mojo::Exception overloads the following operators. .SS "bool" .IX Subsection "bool" .Vb 1 \& my $bool = !!$e; .Ve .PP Always true. .SS "stringify" .IX Subsection "stringify" .Vb 1 \& my $str = "$e"; .Ve .PP Alias for \*(L"to_string\*(R". .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious, Mojolicious::Guides, .