1 # generate-php-exceptions: generate error handling code for PHP bindings
2 my $copyright = <<'END';
3 Copyright 2006,2007,2010,2011,2012,2016 Olly Betts
4 Copyright 2007 Lemur Consulting Ltd
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 open FD, ">except.i" or die $!;
26 $copyright =~ s/^/ */mg;
31 * \@brief Custom PHP exception handling.
33 /* Warning: This file is generated by $0
34 * - do not modify directly!
42 #include <zend_exceptions.h>
45 XapianExceptionHandler()
48 // Rethrow so we can look at the exception if it was a Xapian::Error.
50 } catch (const Xapian::Error &e) {
51 // FIXME: It would be nicer to make the exceptions PHP classes
52 // corresponding to the C++ Xapian::Error class hierarchy.
53 zend_throw_exception(NULL, e.get_description().c_str(),
55 } catch (const std::exception &e) {
56 zend_throw_exception_ex(NULL, SWIG_UnknownError,
57 "std::exception %s", e.what());
59 zend_throw_exception(NULL, "unknown error in Xapian",
65 /* Functions and methods which are marked as "nothrow": */
69 exception_data::for_each_nothrow(sub { print FD "%exception $_[0];\n" });
77 XapianExceptionHandler();