1 ///////////////////////////////////////////////////////////////////////////////
\r
3 // File : $Id: exception.cpp,v 1.1 2007/05/05 17:00:42 faust Exp $
\r
4 // Subject : IBPP, Initialization of the library
\r
6 ///////////////////////////////////////////////////////////////////////////////
\r
8 // (C) Copyright 2000-2006 T.I.P. Group S.A. and the IBPP Team (www.ibpp.org)
\r
10 // The contents of this file are subject to the IBPP License (the "License");
\r
11 // you may not use this file except in compliance with the License. You may
\r
12 // obtain a copy of the License at http://www.ibpp.org or in the 'license.txt'
\r
13 // file which must have been distributed along with this file.
\r
15 // This software, distributed under the License, is distributed on an "AS IS"
\r
16 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
\r
17 // License for the specific language governing rights and limitations
\r
18 // under the License.
\r
20 ///////////////////////////////////////////////////////////////////////////////
\r
23 // * Tabulations should be set every four characters when editing this file.
\r
25 ///////////////////////////////////////////////////////////////////////////////
\r
28 #pragma warning(disable: 4786 4996)
\r
30 #pragma warning(disable: 4702)
\r
43 using namespace ibpp_internals;
\r
45 // None of the exception classes methods are implemented inline, because they
\r
46 // are all declared throw() and Borland compilers at least, but possibly some
\r
47 // others emit a warning like "W8026 - functions with exception specification
\r
48 // are not expanded inline". Nothing we have to worry about, but we don't want
\r
49 // people concerned by such warnings.
\r
51 IBPP::Exception::~Exception() throw()
\r
55 IBPP::LogicException::~LogicException() throw()
\r
59 IBPP::SQLException::~SQLException() throw()
\r
63 IBPP::WrongType::~WrongType() throw()
\r
68 // (((((((( ExceptionBase Implementation ))))))))
\r
71 void ExceptionBase::buildErrorMessage(const char* message)
\r
73 if (! mContext.empty())
\r
74 mWhat.append(_("Context: ")).append(mContext).append("\n");
\r
76 if (message != 0 && *message != 0 )
\r
77 mWhat.append(_("Message: ")).append(message).append("\n");
\r
82 void ExceptionBase::raise(const std::string& context, const char* message, va_list argptr)
\r
84 mContext.assign(context);
\r
89 #if defined(_MSC_VER) || defined(__DMC__)
\r
90 _vsnprintf(buffer, sizeof(buffer)-1, message, argptr);
\r
92 vsnprintf(buffer, sizeof(buffer)-1, message, argptr);
\r
94 buffer[sizeof(buffer)-1] = 0;
\r
96 buildErrorMessage(buffer);
\r
99 buildErrorMessage(0);
\r
102 ExceptionBase::ExceptionBase() throw()
\r
106 ExceptionBase::ExceptionBase(const ExceptionBase& copied) throw()
\r
108 mContext = copied.mContext;
\r
109 mWhat = copied.mWhat;
\r
112 ExceptionBase& ExceptionBase::operator=(const ExceptionBase& copied) throw()
\r
114 mContext = copied.mContext;
\r
115 mWhat = copied.mWhat;
\r
119 ExceptionBase::ExceptionBase(const std::string& context,
\r
120 const char* message, ...) throw()
\r
123 va_start(argptr, message);
\r
124 mWhat.assign("*** IBPP::Exception ***\n");
\r
125 raise(context, message, argptr);
\r
129 ExceptionBase::~ExceptionBase() throw()
\r
133 const char* ExceptionBase::Origin() const throw()
\r
135 return mContext.c_str();
\r
138 const char* ExceptionBase::ErrorMessage() const throw()
\r
140 return mWhat.c_str();
\r
143 const char* ExceptionBase::what() const throw()
\r
145 return mWhat.c_str();
\r
148 // (((((((( LogicExceptionImpl Implementation ))))))))
\r
150 // The following constructors are small and could be inlined, but for object
\r
151 // code compacity of the library it is much better to have them non-inlined.
\r
152 // The amount of code generated by compilers for a throw is well-enough.
\r
154 LogicExceptionImpl::LogicExceptionImpl() throw()
\r
159 LogicExceptionImpl::LogicExceptionImpl(const LogicExceptionImpl& copied) throw()
\r
160 : IBPP::LogicException(), ExceptionBase(copied)
\r
164 LogicExceptionImpl& LogicExceptionImpl::operator=(const LogicExceptionImpl& copied) throw()
\r
166 ExceptionBase::operator=(copied);
\r
170 LogicExceptionImpl::LogicExceptionImpl(const std::string& context,
\r
171 const char* message, ...) throw()
\r
174 va_start(argptr, message);
\r
175 mWhat.assign("*** IBPP::LogicException ***\n");
\r
176 raise(context, message, argptr);
\r
180 LogicExceptionImpl::~LogicExceptionImpl() throw ()
\r
184 const char* LogicExceptionImpl::Origin() const throw()
\r
186 return ExceptionBase::Origin();
\r
189 const char* LogicExceptionImpl::ErrorMessage() const throw()
\r
191 return ExceptionBase::what();
\r
194 const char* LogicExceptionImpl::what() const throw()
\r
196 return ExceptionBase::what();
\r
199 // (((((((( SQLExceptionImpl Implementation ))))))))
\r
201 SQLExceptionImpl::SQLExceptionImpl() throw()
\r
202 : ExceptionBase(), mSqlCode(0), mEngineCode(0)
\r
206 SQLExceptionImpl::SQLExceptionImpl(const SQLExceptionImpl& copied) throw()
\r
207 : IBPP::SQLException(), ExceptionBase(copied), mSqlCode(copied.mSqlCode),
\r
208 mEngineCode(copied.mEngineCode)
\r
212 SQLExceptionImpl& SQLExceptionImpl::operator=(const SQLExceptionImpl& copied) throw()
\r
214 ExceptionBase::operator=(copied);
\r
215 mSqlCode = copied.mSqlCode;
\r
216 mEngineCode = copied.mEngineCode;
\r
220 SQLExceptionImpl::SQLExceptionImpl(const IBS& status, const std::string& context,
\r
221 const char* message, ...) throw()
\r
224 va_start(argptr, message);
\r
225 mWhat.assign("*** IBPP::SQLException ***\n");
\r
226 raise(context, message, argptr);
\r
228 mSqlCode = status.SqlCode();
\r
229 mEngineCode = status.EngineCode();
\r
230 mWhat.append(status.ErrorMessage());
\r
233 SQLExceptionImpl::~SQLExceptionImpl() throw ()
\r
237 const char* SQLExceptionImpl::Origin() const throw()
\r
239 return ExceptionBase::Origin();
\r
242 const char* SQLExceptionImpl::ErrorMessage() const throw()
\r
244 return ExceptionBase::what();
\r
247 const char* SQLExceptionImpl::what() const throw()
\r
249 return ExceptionBase::what();
\r
252 int SQLExceptionImpl::SqlCode() const throw()
\r
257 int SQLExceptionImpl::EngineCode() const throw()
\r
259 return mEngineCode;
\r
262 // (((((((( WrongTypeImpl Implementation ))))))))
\r
264 // The following constructors are small and could be inlined, but for object
\r
265 // code compacity of the library it is much better to have them non-inlined.
\r
266 // The amount of code generated by compilers for a throw is well-enough.
\r
268 WrongTypeImpl::WrongTypeImpl() throw()
\r
269 : IBPP::WrongType(), ExceptionBase()
\r
273 WrongTypeImpl::WrongTypeImpl(const WrongTypeImpl& copied) throw()
\r
274 : IBPP::WrongType(), ExceptionBase(copied)
\r
278 WrongTypeImpl& WrongTypeImpl::operator=(const WrongTypeImpl& copied) throw()
\r
280 ExceptionBase::operator=(copied);
\r
284 WrongTypeImpl::WrongTypeImpl(const std::string& context, int sqlType, IITYPE varType,
\r
285 const char* message, ...) throw()
\r
288 va_start(argptr, message);
\r
289 mWhat.assign("*** IBPP::WrongType ***\n");
\r
290 raise(context, message, argptr);
\r
294 switch (sqlType & ~1)
\r
296 case SQL_TEXT : info.append("CHAR"); break;
\r
297 case SQL_VARYING : info.append("VARCHAR"); break;
\r
298 case SQL_SHORT : info.append("SMALLINT"); break;
\r
299 case SQL_LONG : info.append("INTEGER"); break;
\r
300 case SQL_INT64 : info.append("BIGINT"); break;
\r
301 case SQL_FLOAT : info.append("FLOAT"); break;
\r
302 case SQL_DOUBLE : info.append("DOUBLE"); break;
\r
303 case SQL_TIMESTAMP : info.append("TIMESTAMP"); break;
\r
304 case SQL_TYPE_DATE : info.append("DATE"); break;
\r
305 case SQL_TYPE_TIME : info.append("TIME"); break;
\r
306 case SQL_BLOB : info.append("BLOB"); break;
\r
307 case SQL_ARRAY : info.append("ARRAY"); break;
\r
309 info.append(" ").append(_(" and ")).append(" ");
\r
312 case ivArray : info.append("Array"); break;
\r
313 case ivBlob : info.append("Blob"); break;
\r
314 case ivDate : info.append("Date"); break;
\r
315 case ivTime : info.append("Time"); break;
\r
316 case ivTimestamp : info.append("Timestamp"); break;
\r
317 case ivString : info.append("std::string"); break;
\r
318 case ivInt16 : info.append("int16_t"); break;
\r
319 case ivInt32 : info.append("int32_t"); break;
\r
320 case ivInt64 : info.append("int64_t"); break;
\r
321 case ivFloat : info.append("float"); break;
\r
322 case ivDouble : info.append("double"); break;
\r
323 case ivBool : info.append("bool"); break;
\r
324 case ivDBKey : info.append("DBKey"); break;
\r
325 case ivByte : info.append("int8_t"); break;
\r
327 mWhat.append(info).append("\n");
\r
330 WrongTypeImpl::~WrongTypeImpl() throw ()
\r
334 const char* WrongTypeImpl::Origin() const throw()
\r
336 return ExceptionBase::Origin();
\r
339 const char* WrongTypeImpl::ErrorMessage() const throw()
\r
341 return ExceptionBase::what();
\r
344 const char* WrongTypeImpl::what() const throw()
\r
346 return ExceptionBase::what();
\r