1 # generate-tcl-exceptions: generate error handling code for Tcl bindings
2 my $copyright = <<'END';
3 Copyright (c) 2006,2007,2011,2012 Olly Betts
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 open FD, ">except.i" or die $!;
25 $copyright =~ s/^/ */mg;
30 * \@brief Custom Tcl exception handling.
32 /* Warning: This file is generated by $0
33 * - do not modify directly!
42 static int XapianTclHandleError(Tcl_Interp * interp, const Xapian::Error &e) {
43 Tcl_ResetResult(interp);
44 Tcl_SetErrorCode(interp, "XAPIAN", e.get_type(), NULL);
45 Tcl_AppendResult(interp, e.get_msg().c_str(), NULL);
49 static int XapianTclHandleError(Tcl_Interp * interp, const std::exception &e) {
50 Tcl_ResetResult(interp);
51 Tcl_SetErrorCode(interp, "std::exception", NULL);
52 Tcl_AppendResult(interp, e.what(), NULL);
56 static int XapianTclHandleError(Tcl_Interp * interp) {
57 Tcl_ResetResult(interp);
58 Tcl_SetErrorCode(interp, "XAPIAN ?", NULL);
59 Tcl_AppendResult(interp, "Unknown Error", NULL);
65 /* Functions and methods which are marked as "nothrow": */
69 exception_data::for_each_nothrow(sub { print FD "%exception $_[0];\n" });
76 } catch (const Xapian::Error &e) {
77 return XapianTclHandleError(interp, e);
78 } catch (const std::exception &e) {
79 return XapianTclHandleError(interp, e);
81 return XapianTclHandleError(interp);