1 # generate-perl-exceptions: generate error handling code for Perl bindings
2 my $copyright = <<'END';
3 Copyright (C) 2003,2004,2006,2007,2008,2011,2012,2013 Olly Betts
4 Copyright (C) 2007 Lemur Consulting Ltd
5 Copyright (C) 2007 Richard Boulton
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 my @allclasses = (@baseclasses, @classes);
27 open FD, ">except.i" or die $!;
29 $copyright =~ s/^/ */mg;
32 /** \@file perl/except.i
33 * \@brief Custom Perl exception handling.
35 /* Warning: This file is generated by $0
36 * - do not modify directly!
45 %exceptionclass Error;
49 my ($class, $parent, $comment) = split /\t/, $_, 3;
50 print FD "%exceptionclass $class;\n";
55 %include "xapian/error.h"
59 void handle_exception() {
64 for (reverse @allclasses) {
65 my ($class, $parent, $comment) = split /\t/, $_, 3;
67 } catch (const Xapian::$class &e) {
68 void * p = (void *) new Xapian::$class(e);
70 SV * sv = sv_newmortal();
71 sv_setref_pv(sv, "Xapian::$class", p);
74 sv_setref_pv(ERRSV, "Xapian::$class", p);
77 sv_setref_pv(get_sv("@", TRUE), "Xapian::$class", p);
84 } catch (const std::exception& e) {
85 croak("std::exception: %s", e.what());
87 croak("something terrible happened");
93 /* Functions and methods which are marked as "nothrow": */
97 exception_data::for_each_nothrow(sub { print FD "%exception $_[0];\n" });
105 Xapian::handle_exception();