From aacb216c560123577f570be77b4efe9c1550cc61 Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Tue, 14 Apr 2015 18:04:59 +0300 Subject: [PATCH] Bug 13995 - Proper Exception handling try { Koha::Exception::BadSystemPreference->throw(error => 'Syspref DisplayIconsXSLT is not a valid boolean'); } catch { if (blessed($_) && $_->isa('Koha::Exception::BadSystemPreference')) { print $_->as_string(); warn $_->error, "\n", $_->trace->as_string, "\n"; } else { $_->rethrow(); } } --- Koha/Exception/BadSystemPreference.pm | 29 +++++++++++++++++++++++++++++ Koha/Exception/ConnectionFailed.pm | 28 ++++++++++++++++++++++++++++ Koha/Exception/LoginFailed.pm | 28 ++++++++++++++++++++++++++++ Koha/Exception/NoSystemPreference.pm | 29 +++++++++++++++++++++++++++++ Koha/Exception/UnknownProtocol.pm | 28 ++++++++++++++++++++++++++++ 5 files changed, 142 insertions(+) create mode 100644 Koha/Exception/BadSystemPreference.pm create mode 100644 Koha/Exception/ConnectionFailed.pm create mode 100644 Koha/Exception/LoginFailed.pm create mode 100644 Koha/Exception/NoSystemPreference.pm create mode 100644 Koha/Exception/UnknownProtocol.pm diff --git a/Koha/Exception/BadSystemPreference.pm b/Koha/Exception/BadSystemPreference.pm new file mode 100644 index 0000000..6d24039 --- /dev/null +++ b/Koha/Exception/BadSystemPreference.pm @@ -0,0 +1,29 @@ +package Koha::Exception::BadSystemPreference; + +# Copyright 2015 Vaara-kirjastot +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Exception::Class ( + 'Koha::Exception::BadSystemPreference' => { + description => 'System preference value is incomprehensible', + fields => ['syspref'], + }, +); + +return 1; \ No newline at end of file diff --git a/Koha/Exception/ConnectionFailed.pm b/Koha/Exception/ConnectionFailed.pm new file mode 100644 index 0000000..1c35949 --- /dev/null +++ b/Koha/Exception/ConnectionFailed.pm @@ -0,0 +1,28 @@ +package Koha::Exception::ConnectionFailed; + +# Copyright 2015 Vaara-kirjastot +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Exception::Class ( + 'Koha::Exception::ConnectionFailed' => { + description => 'Connecting to host failed', + }, +); + +return 1; \ No newline at end of file diff --git a/Koha/Exception/LoginFailed.pm b/Koha/Exception/LoginFailed.pm new file mode 100644 index 0000000..561d5c3 --- /dev/null +++ b/Koha/Exception/LoginFailed.pm @@ -0,0 +1,28 @@ +package Koha::Exception::LoginFailed; + +# Copyright 2015 Vaara-kirjastot +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Exception::Class ( + 'Koha::Exception::LoginFailed' => { + description => 'Login to host failed', + }, +); + +return 1; \ No newline at end of file diff --git a/Koha/Exception/NoSystemPreference.pm b/Koha/Exception/NoSystemPreference.pm new file mode 100644 index 0000000..ad6f0b8 --- /dev/null +++ b/Koha/Exception/NoSystemPreference.pm @@ -0,0 +1,29 @@ +package Koha::Exception::NoSystemPreference; + +# Copyright 2015 Vaara-kirjastot +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Exception::Class ( + 'Koha::Exception::NoSystemPreference' => { + description => 'Required system preference is not set', + fields => ['syspref'], + }, +); + +return 1; \ No newline at end of file diff --git a/Koha/Exception/UnknownProtocol.pm b/Koha/Exception/UnknownProtocol.pm new file mode 100644 index 0000000..0365f2e --- /dev/null +++ b/Koha/Exception/UnknownProtocol.pm @@ -0,0 +1,28 @@ +package Koha::Exception::UnknownProtocol; + +# Copyright 2015 Vaara-kirjastot +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Exception::Class ( + 'Koha::Exception::UnknownProtocol' => { + description => 'Protocol is not known', + }, +); + +return 1; \ No newline at end of file -- 1.7.9.5