FirteX-高性能全文索引和检索平台

API Documentation


首页 | 名字空间列表 | 类继承关系 | 组合类型列表 | $(BL\录(B | 文件列表 | 名字空间成员 | 组合类型成员 | 文件成员

Exception.h

浏览该文件的文档。
00001 //
00002 // Copyright(C) 2005--2006 Institute of Computing Tech, Chinese Academy of Sciences. 
00003 // All rights reserved.
00004 // This file is part of FirteX (www.firtex.org)
00005 //
00006 // Use of the FirteX is subject to the terms of the software license set forth in 
00007 // the LICENSE file included with this software, and also available at
00008 // http://www.firtex.org/license.html
00009 //
00010 // Author       : 郭瑞杰(GuoRuijie)
00011 // Email        : ruijieguo@software.ict.ac.cn,ruijieguo@gmail.com
00012 // Created      : 2005/12/16
00013 //
00014 #ifndef __EXCEPTION_H
00015 #define __EXCEPTION_H
00016 
00017 #if _MSC_VER > 1000
00018 #pragma once
00019 #endif // _MSC_VER > 1000
00020 
00021 #include <iostream>
00022 #include <string>
00023 #include <sstream>
00024 using namespace std;
00025 
00026 
00027 namespace firtex
00028 {
00029         namespace utility
00030         {               
00031 
00032                 typedef unsigned short exception_type;
00033                 class CFirteException
00034                 {
00035                 public:
00036                         CFirteException(exception_type code,const string& msg = "") :m_code(code),m_what(s_errorStrings[code] + ":" + msg)
00037                         {
00038                         }
00039                         CFirteException(exception_type code,const string& msg,const string& file,int line) : m_code(code)
00040                         {
00041                                 stringstream ss;
00042                                 ss << s_errorStrings[code] << ":" << msg << " at file: " << file << ",line:" << line;
00043                                 m_what = ss.str();
00044                         }
00045                         CFirteException(const CFirteException& clone):m_code(clone.m_code),m_what(clone.m_what)
00046                         {
00047                         }
00048                         CFirteException&operator=(const CFirteException& right)
00049                         {
00050                                 m_code = right.m_code;
00051                                 m_what = right.m_what;
00052                         }
00053                         virtual~CFirteException(){}
00054 
00055                         enum
00056                         {
00057                                 UNKNOWN_ERROR,
00058                                 GENERIC_ERROR,
00059                                 MISSING_PARAMETER_ERROR,
00060                                 BAD_PARAMETER_ERROR,
00061                                 FILEIO_ERROR,
00062                                 RUNTIME_ERROR,
00063                                 OUTOFMEM_ERROR,
00064                                 ILLEGALARGUMENT_ERROR,
00065                                 UNSUPPORTED_ERROR,
00066                                 CAST_ERROR,
00067                                 OUTOFORDER_ERROR,
00068                                 OUTOFRANGE_ERROR,
00069                                 PARSE_ERROR,
00070                                 ANALYZE_ERROR,
00071                                 INDEX_COLLAPSE_ERROR,
00072                                 QUERY_PARSE_ERROR,
00073                                 VERSION_ERROR,
00074                                 ASSERT_ERROR,
00075                                 NUMBER_FORMAT_ERROR,
00076                                 NUM_ERRORS
00077                         };
00078                 public:
00079                         virtual const char*             what(){return m_what.c_str();}
00080                         virtual exception_type  code(){return m_code;}
00081                 protected:
00082                         static string s_errorStrings[NUM_ERRORS];
00083                         string                  m_what;
00084                         exception_type  m_code;
00085                 };              
00086 
00087                 class CIllegalArgumentException : public CFirteException
00088                 {
00089                 public:
00090                         CIllegalArgumentException(const string& msg):CFirteException(ILLEGALARGUMENT_ERROR,msg)
00091                         {
00092                         }
00093                         ~CIllegalArgumentException(){}          
00094                 };              
00095 
00096                 class CUnsupportedOperationException : public CFirteException
00097                 {
00098                 public:
00099                         CUnsupportedOperationException(const string& msg):CFirteException(UNSUPPORTED_ERROR,msg)
00100                         {
00101                         }
00102                         ~CUnsupportedOperationException(){}             
00103                 };              
00104 
00105                 class CFileIOException : public CFirteException
00106                 {
00107                 public:
00108                         CFileIOException(const string& msg):CFirteException(FILEIO_ERROR,msg)
00109                         {
00110                         }
00111                         ~CFileIOException(){}           
00112                 };              
00113 
00114                 #define FIRTEX_THROW1(code) throw CFirteException(CFirteException::code)
00115                 #define FIRTEX_THROW2(code,msg) throw CFirteException(CFirteException::code,msg)                
00116                 #define FIRTEX_THROW3(code,msg) throw CFirteException(CFirteException::code,msg,__FILE__, __LINE__)             
00117                 #define FIRTEX_THROW_LINE(code,msg,file,line) throw CFirteException(CFirteException::code,msg,file,line)
00118                 #define FIRTEX_RETHROW(e) throw CFirteException(e)
00119 
00120         #ifdef _DEBUG
00121                 #define FIRTEX_ASSERT(exp,msg) if(!(exp)){throw CFirteException(CFirteException::ASSERT_ERROR,msg,__FILE__, __LINE__);}
00122         #else 
00123                 #define FIRTEX_ASSERT(exp,msg)
00124         #endif
00125         }
00126 }
00127 #endif
00128 

http://www.firtex.org http://www.sourceforge.net/projects/firtex