activemq-cpp-3.3.0

src/main/activemq/exceptions/BrokerException.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 
00018 #ifndef _ACTIVEMQ_EXCEPTIONS_BROKEREXCEPTION_H_
00019 #define _ACTIVEMQ_EXCEPTIONS_BROKEREXCEPTION_H_
00020 
00021 #include <activemq/util/Config.h>
00022 #include <activemq/exceptions/ActiveMQException.h>
00023 #include <activemq/commands/BrokerError.h>
00024 #include <sstream>
00025 
00026 namespace activemq{
00027 namespace exceptions{
00028 
00029     class AMQCPP_API BrokerException : public exceptions::ActiveMQException {
00030     public:
00031 
00032         BrokerException() throw() {}
00033 
00034         BrokerException( const exceptions::ActiveMQException& ex ) throw()
00035             : exceptions::ActiveMQException(){
00036             *( exceptions::ActiveMQException* )this = ex;
00037         }
00038 
00039         BrokerException( const BrokerException& ex ) throw()
00040             : exceptions::ActiveMQException(){
00041             *( exceptions::ActiveMQException* )this = ex;
00042         }
00043 
00044         BrokerException( const char* file, const int lineNumber,
00045                          const char* msg, ... ) throw()
00046           : exceptions::ActiveMQException() {
00047 
00048             va_list vargs;
00049             va_start( vargs, msg );
00050             buildMessage( msg, vargs );
00051 
00052             // Set the first mark for this exception.
00053             setMark( file, lineNumber );
00054         }
00055 
00056         BrokerException( const char* file, const int lineNumber,
00057                          const commands::BrokerError* error ) throw()
00058           : exceptions::ActiveMQException() {
00059 
00060             std::ostringstream ostream;
00061             ostream << "*** BEGIN SERVER-SIDE STACK TRACE ***" << std::endl;
00062             ostream << "Message: " << error->getMessage() << std::endl;
00063             if( error->getCause() != NULL ) {
00064                 ostream << "Cause: " << error->getCause()->toString() << std::endl;
00065             }
00066             ostream << "Exception Class " << error->getExceptionClass() << std::endl;
00067 
00068             for( std::size_t ix = 0; ix< error->getStackTraceElements().size(); ++ix ){
00069                 ostream << "\t[FILE: " << error->getStackTraceElements()[ix]->FileName
00070                         << ", LINE: " << error->getStackTraceElements()[ix]->LineNumber
00071                         << "] occurred in: " << error->getStackTraceElements()[ix]->ClassName
00072                         << "." << error->getStackTraceElements()[ix]->MethodName
00073                         << std::endl;
00074             }
00075 
00076             ostream << "*** END SERVER-SIDE STACK TRACE ***";
00077 
00078             setMessage( ostream.str().c_str() );
00079             setMark( file, lineNumber );
00080         }
00081 
00087         virtual BrokerException* clone() const{
00088             return new BrokerException( *this );
00089         }
00090 
00091         virtual ~BrokerException() throw() {}
00092     };
00093 
00094 }}
00095 
00096 #endif /*_ACTIVEMQ_EXCEPTIONS_BROKEREXCEPTION_H_*/