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;
33 * \@brief Custom Perl exception handling.
35 /* Warning: This file is generated by $0
36 * - do not modify directly!
45 %exceptionclass Error;
50 print FD "%exceptionclass $class;\n";
55 %ignore Xapian::Error::Error(const Error&);
56 %include "xapian/error.h"
60 void handle_exception() {
65 for (reverse @allclasses) {
68 } catch (const Xapian::$class &e) {
69 void * p = (void *) new Xapian::$class(e);
71 SV * sv = sv_newmortal();
72 sv_setref_pv(sv, "Xapian::$class", p);
75 sv_setref_pv(ERRSV, "Xapian::$class", p);
78 sv_setref_pv(get_sv("@", TRUE), "Xapian::$class", p);
85 } catch (const std::exception& e) {
86 croak("std::exception: %s", e.what());
88 croak("something terrible happened");
94 /* Functions and methods which are marked as "nothrow": */
98 exception_data::for_each_nothrow(sub { print FD "%exception $_[0];\n" });
106 Xapian::handle_exception();