1 # generate-generic-exceptions: generate generic error handling code
2 my $copyright = <<'END';
3 Copyright (C) 2004,2005,2006,2007,2011,2012,2018 Olly Betts
4 Copyright (C) 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
25 open FD, ">generic/except.i" or die $!;
27 $copyright =~ s/^/ */mg;
32 * \@brief Language independent exception handling.
34 /* Warning: This file is generated by $0
35 * - do not modify directly!
39 /* This file is included for any languages which don't have language specific
40 * handling for exceptions.
48 static int XapianExceptionHandler(string & msg) {
50 // Rethrow so we can look at the exception if it was a Xapian::Error.
52 } catch (const Xapian::Error &e) {
53 msg = e.get_description();
55 // Re-rethrow the previous exception so we can handle the type in a
56 // fine-grained way, but only in one place to avoid bloating the
59 } catch (const Xapian::InvalidArgumentError &) {
60 return SWIG_ValueError;
61 } catch (const Xapian::RangeError &) {
62 return SWIG_IndexError;
63 } catch (const Xapian::DatabaseError &) {
65 } catch (const Xapian::NetworkError &) {
67 } catch (const Xapian::InternalError &) {
68 return SWIG_RuntimeError;
69 } catch (const Xapian::RuntimeError &) {
70 return SWIG_RuntimeError;
72 return SWIG_UnknownError;
74 } catch (const std::exception &e) {
75 msg = "std::exception: ";
78 msg = "unknown error in Xapian";
80 return SWIG_UnknownError;
84 /* Functions and methods which are marked as "nothrow": */
88 exception_data::for_each_nothrow(sub { print FD "%exception $_[0];\n" });
97 int code = XapianExceptionHandler(msg);
98 SWIG_exception(code, msg.c_str());