1 //@copyright_begin
2 // ================================================================
3 // Copyright Notice
4 // Copyright (C) 1998-2004 by Joe Linoff
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining
7 // a copy of this software and associated documentation files (the
8 // "Software"), to deal in the Software without restriction, including
9 // without limitation the rights to use, copy, modify, merge, publish,
10 // distribute, sublicense, and/or sell copies of the Software, and to
11 // permit persons to whom the Software is furnished to do so, subject to
12 // the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 // IN NO EVENT SHALL JOE LINOFF BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 // OTHER DEALINGS IN THE SOFTWARE.
24 //
25 // Comments and suggestions are always welcome.
26 // Please report bugs to http://ccdoc.sourceforge.net/ccdoc
27 // ================================================================
28 //@copyright_end
29 
30 // ================================================================
31 // This static variable allows the header version
32 // to be queried at runtime.
33 // ================================================================
34 namespace {
35   char ccdoc_rcsid[] = "$Id: exceptions.cc,v 1.6 2004/09/30 04:16:01 jlinoff Exp $";
36 }
37 
38 #include "exceptions.h"
39 #include <iostream>
40 #include <cstdio>
41 
42 // ================================================================
43 // Default constructor.
44 // ================================================================
base()45 ccdoc::exceptions::base::base() {
46 }
47 // ================================================================
48 // Id based constructor.
49 // ================================================================
base(const char * id,const char * file,int lineno,const char * msg)50 ccdoc::exceptions::base::base(const char* id,
51 			      const char* file,
52 			      int lineno,
53 			      const char* msg)
54 {
55   char nbuf[32];
56   sprintf(nbuf,"%d",lineno);
57   ccdoc_assert(file);
58   ccdoc_assert(msg);
59   m_msg = "EXCEPTION:";
60   m_msg += id;
61   m_msg += ":";
62   m_msg += file;
63   m_msg += ":";
64   m_msg += nbuf;
65   m_msg += ": ";
66   m_msg += msg;
67 }
68 // ================================================================
69 // Destructor.
70 // ================================================================
~base()71 ccdoc::exceptions::base::~base() {
72 }
73 // ================================================================
74 // Report
75 // ================================================================
report() const76 void ccdoc::exceptions::base::report() const {
77   cerr << endl << m_msg.c_str() << endl;
78 }
79 
80 // ================================================================
81 // assert_true
82 // ================================================================
assert_true(const char * file,int lineno,const char * expr)83 ccdoc::exceptions::assert_true::assert_true(const char* file,
84 					    int lineno,
85 					    const char* expr)
86   : ccdoc::exceptions::base("assertion failed",file,lineno,expr)
87 {
88 }
89 
90 // ================================================================
91 // invalid_database
92 // ================================================================
invalid_database(const char * file,int lineno,const char * dbfile,const char * msg)93 ccdoc::exceptions::invalid_database::invalid_database(const char* file,
94 						      int lineno,
95 						      const char* dbfile,
96 						      const char* msg)
97   : ccdoc::exceptions::base("invalid database",file,lineno,dbfile)
98 {
99   ccdoc_assert(msg);
100   m_msg += " ";
101   m_msg += msg;
102 }
103 
104 // ================================================================
105 // duplicate_name
106 // ================================================================
duplicate_name(const char * file,int lineno,const char * name,const char * msg)107 ccdoc::exceptions::duplicate_name::duplicate_name(const char* file,
108 						  int lineno,
109 						  const char* name,
110 						  const char* msg)
111   : ccdoc::exceptions::base("duplicate name",file,lineno,name)
112 {
113   ccdoc_assert(msg);
114   m_msg += " ";
115   m_msg += msg;
116 }
117 // ================================================================
118 // duplicate_name
119 // ================================================================
120 ccdoc::exceptions::
unwriteable_output_file(const char * file,int lineno,const char * name)121 unwriteable_output_file::unwriteable_output_file(const char* file,
122 						 int lineno,
123 						 const char* name)
124   : ccdoc::exceptions::base("unwriteable output file",file,lineno,name)
125 {
126 }
127