activemq-cpp-3.3.0

src/main/decaf/lang/Exception.h

Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 #ifndef _DECAF_LANG_EXCEPTION_EXCEPTION_H_
00018 #define _DECAF_LANG_EXCEPTION_EXCEPTION_H_
00019 
00020 #ifdef _WIN32
00021 #pragma warning( disable: 4251 )
00022 #endif
00023 
00024 #include <decaf/lang/Throwable.h>
00025 #include <decaf/lang/exceptions/ExceptionDefines.h>
00026 #include <decaf/util/Config.h>
00027 #include <stdarg.h>
00028 #include <sstream>
00029 
00030 namespace decaf{
00031 namespace lang{
00032 
00033     /*
00034      * Base class for all exceptions.
00035      */
00036     class DECAF_API Exception : public Throwable {
00037     protected:
00038 
00042         std::string message;
00043 
00047         std::exception* cause;
00048 
00052         std::vector< std::pair< std::string, int> > stackTrace;
00053 
00054     public:
00055 
00059         Exception() throw();
00060 
00067         Exception( const Exception& ex ) throw();
00068 
00076         Exception( const std::exception* cause ) throw();
00077 
00087         Exception( const char* file, const int lineNumber,
00088                    const char* msg, ... ) throw();
00089 
00100         Exception( const char* file, const int lineNumber,
00101                    const std::exception* cause,
00102                    const char* msg, ... ) throw();
00103 
00104         virtual ~Exception() throw();
00105 
00110         virtual std::string getMessage() const{
00111             return message;
00112         }
00113 
00123         virtual const std::exception* getCause() const {
00124             return this->cause;
00125         }
00126 
00132         virtual void initCause( const std::exception* cause );
00133 
00138         virtual const char* what() const throw (){
00139             return message.c_str();
00140         }
00141 
00147         virtual void setMessage( const char* msg, ... );
00148 
00154         virtual void setMark( const char* file, const int lineNumber );
00155 
00162         virtual Exception* clone() const;
00163 
00171         virtual std::vector< std::pair< std::string, int> > getStackTrace() const;
00172 
00176         virtual void printStackTrace() const;
00177 
00182         virtual void printStackTrace( std::ostream& stream ) const;
00183 
00188         virtual std::string getStackTraceString() const;
00189 
00194         Exception& operator =( const Exception& ex );
00195 
00196     protected:
00197 
00198         virtual void setStackTrace(
00199             const std::vector< std::pair< std::string, int> >& trace );
00200 
00201         virtual void buildMessage( const char* format, va_list& vargs );
00202 
00203    };
00204 
00205 }}
00206 
00207 #endif /*_DECAF_LANG_EXCEPTION_EXCEPTION_H_*/