1 # generate-php-exceptions: generate error handling code for PHP bindings
2 my $copyright = <<'END';
3 Copyright 2006,2007,2010,2011,2012 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;
30 /** \@file php/except.i
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()
50 // Rethrow so we can look at the exception if it was a Xapian::Error.
52 } catch (const Xapian::Error &e) {
53 // FIXME: It would be nicer to make the exceptions PHP classes
54 // corresponding to the C++ Xapian::Error class hierarchy.
55 msg = e.get_description();
56 } catch (const std::exception &e) {
57 msg = "std::exception: ";
60 msg = "unknown error in Xapian";
62 // zend_throw_exception takes a non-const char * parameter (sigh).
63 char * message = const_cast<char*>(msg.c_str());
64 zend_throw_exception(NULL, message, SWIG_UnknownError TSRMLS_CC);
68 /* Functions and methods which are marked as "nothrow": */
72 exception_data::for_each_nothrow(sub { print FD "%exception $_[0];\n" });
80 XapianExceptionHandler();