New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Exception.pm in branches/UKMO/dev_r5518_fa_am_dt_deltadelta_toa/NEMOGCM/EXTERNAL/fcm/lib/Fcm – NEMO

source: branches/UKMO/dev_r5518_fa_am_dt_deltadelta_toa/NEMOGCM/EXTERNAL/fcm/lib/Fcm/Exception.pm @ 7051

Last change on this file since 7051 was 7051, checked in by kuniko, 7 years ago

Removed $Id ...

File size: 2.2 KB
Line 
1# ------------------------------------------------------------------------------
2# (C) Crown copyright Met Office. All rights reserved.
3# For further details please refer to the file COPYRIGHT.txt
4# which you should have received as part of this distribution.
5# ------------------------------------------------------------------------------
6use strict;
7use warnings;
8
9package Fcm::Exception;
10use overload (q{""} => \&as_string);
11
12use Scalar::Util qw{blessed};
13
14# ------------------------------------------------------------------------------
15# Returns true if $e is a blessed instance of this class.
16sub caught {
17    my ($class, $e) = @_;
18    return (blessed($e) && $e->isa($class));
19}
20
21# ------------------------------------------------------------------------------
22# Constructor
23sub new {
24    my ($class, $args_ref) = @_;
25    return bless(
26        {message => q{unknown problem}, ($args_ref ? %{$args_ref} : ())},
27        $class,
28    );
29}
30
31# ------------------------------------------------------------------------------
32# Returns a string representation of this exception
33sub as_string {
34    my ($self) = @_;
35    return sprintf("%s: %s\n", blessed($self), $self->get_message());
36}
37
38# ------------------------------------------------------------------------------
39# Returns the message of this exception
40sub get_message {
41    my ($self) = @_;
42    return $self->{message};
43}
44
451;
46__END__
47
48=head1 NAME
49
50Fcm::Exception
51
52=head1 SYNOPSIS
53
54    use Fcm::Exception;
55    eval {
56        croak(Fcm::Exception->new({message => $message}));
57    };
58    if ($@) {
59        if (Fcm::Exception->caught($@)) {
60            print({STDERR} $@);
61        }
62    }
63
64=head1 DESCRIPTION
65
66This exception is raised when there is a generic problem in FCM.
67
68=head1 METHODS
69
70=over 4
71
72=item $class->caught($e)
73
74Returns true if $e is a blessed instance of this class.
75
76=item $class->new({message=E<gt>$message})
77
78Returns a new instance of this exception. Its first argument must be a
79reference to a hash containing the detailed I<message> of the exception.
80
81=item $e->as_string()
82
83Returns a string representation of this exception.
84
85=item $e->get_message()
86
87Returns the detailed message of this exception.
88
89=back
90
91=head1 COPYRIGHT
92
93E<169> Crown copyright Met Office. All rights reserved.
94
95=cut
Note: See TracBrowser for help on using the repository browser.