1 # generate-generic-exceptions: generate generic error handling code
2 my $copyright = <<'END';
3 Copyright (C) 2004,2005,2006,2007,2011,2012 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;
31 /** \@file generic/except.i
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 // Language interface files can #define XapianException before including this
49 // file to override this.
50 #ifndef XapianException
51 # define XapianException(TYPE, MSG) SWIG_exception((TYPE), (MSG).c_str())
54 static int XapianExceptionHandler(string & msg) {
56 // Rethrow so we can look at the exception if it was a Xapian::Error.
58 } catch (const Xapian::Error &e) {
59 msg = e.get_description();
61 // Re-rethrow the previous exception so we can handle the type in a
62 // fine-grained way, but only in one place to avoid bloating the
65 } catch (const Xapian::InvalidArgumentError &) {
66 return SWIG_ValueError;
67 } catch (const Xapian::RangeError &) {
68 return SWIG_IndexError;
69 } catch (const Xapian::DatabaseError &) {
71 } catch (const Xapian::NetworkError &) {
73 } catch (const Xapian::InternalError &) {
74 return SWIG_RuntimeError;
75 } catch (const Xapian::RuntimeError &) {
76 return SWIG_RuntimeError;
78 return SWIG_UnknownError;
80 } catch (const std::exception &e) {
81 msg = "std::exception: ";
84 msg = "unknown error in Xapian";
86 return SWIG_UnknownError;
90 /* Functions and methods which are marked as "nothrow": */
94 exception_data::for_each_nothrow(sub { print FD "%exception $_[0];\n" });
103 int code = XapianExceptionHandler(msg);
104 XapianException(code, msg);