| 1 | package plenigo::Ex; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | plenigo::Ex - Exception thrown if something went wrong. | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | use plenigo::Ex; | ||
| 10 | |||
| 11 | # Throw an exception | ||
| 12 | |||
| 13 | plenigo::Ex->throw({ code => 100, message => 'Description of the error code.' }); | ||
| 14 | |||
| 15 | =head1 DESCRIPTION | ||
| 16 | |||
| 17 | plenigo::Ex represents an exception. | ||
| 18 | |||
| 19 | =cut | ||
| 20 | |||
| 21 | use Moo; | ||
| 22 | with 'Throwable'; | ||
| 23 | |||
| 24 | our $VERSION = '3.0002'; | ||
| 25 | |||
| 26 | has code => (is=>'ro'); | ||
| 27 | has message => (is=>'ro'); | ||
| 28 | has errorDetails => (is => 'ro'); | ||
| 29 | |||
| 30 | sub e { | ||
| 31 | if (ref($_) eq 'plenigo::Ex') { | ||
| 32 | return $_; | ||
| 33 | } else { | ||
| 34 | chomp; return plenigo::Ex->new(message => $_, code=>0); | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | 1; |