/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /* $Rev$ $Date$ */ #if defined(WIN32) || defined (_WINDOWS) #else #include "tuscany_sca_config.h" #endif #include #if defined(WIN32) || defined (_WINDOWS) || defined (IS_DARWIN) #else #include #endif #include "tuscany/sca/core/Exceptions.h" #include "tuscany/sca/util/Logging.h" using namespace std; namespace tuscany { namespace sca { // ======================================================================== // Constructor // ======================================================================== TuscanyRuntimeException :: TuscanyRuntimeException(const char* name, severity_level sev, const char* msg_text) { severity = sev; location_set = 0; class_name = new char[strlen(name) + 1]; strcpy(class_name,name); message_text = new char[strlen(msg_text)+1]; strcpy(message_text,msg_text); #if defined(WIN32) || defined (_WINDOWS) || defined (IS_DARWIN) #else void* array[25]; stacktrace_size = backtrace(array, 25); stacktrace_symbols = backtrace_symbols(array, stacktrace_size); #endif logwarning("%s raised: %s", class_name, message_text); } // end TuscanyRuntimeException constuctor // ======================================================================== // Constructor // ======================================================================== TuscanyRuntimeException :: TuscanyRuntimeException(const TuscanyRuntimeException& c) { severity = c.getSeverity(); location_set = c.location_set; class_name = new char[strlen(c.getEClassName()) + 1]; strcpy(class_name, c.getEClassName()); message_text = new char[strlen(c.getMessageText())+1]; strcpy(message_text,c.getMessageText()); for (int i=0; i < location_set; i++) { locations[i].file = new char[strlen(c.locations[i].file) + 1]; strcpy(locations[i].file,c.locations[i].file); locations[i].line = c.locations[i].line; locations[i].function = new char[strlen(c.locations[i].function) + 1]; strcpy(locations[i].function, c.locations[i].function); } #if defined(WIN32) || defined (_WINDOWS) || defined (IS_DARWIN) #else void* array[25]; stacktrace_size = backtrace(array, 25); stacktrace_symbols = backtrace_symbols(array, stacktrace_size); #endif logwarning("%s raised: %s", class_name, message_text); } // ======================================================================== // Constructor // ======================================================================== TuscanyRuntimeException :: TuscanyRuntimeException(const SDORuntimeException& c) { class_name = new char[strlen(c.getEClassName()) + 1]; strcpy(class_name, c.getEClassName()); message_text = new char[strlen(c.getMessageText())+1]; strcpy(message_text,c.getMessageText()); switch (c.getSeverity()) { case SDORuntimeException::Normal: severity = Normal; break; case SDORuntimeException::Warning: severity = Warning; break; case SDORuntimeException::Error: severity = Error; break; default: severity = Severe; break; } const char* file = c.getFileName(); unsigned long line = c.getLineNumber(); const char* function = c.getFunctionName(); location_set = 0; if (file) { setLocation(file, line, function); } #if defined(WIN32) || defined (_WINDOWS) || defined (IS_DARWIN) #else void* array[25]; stacktrace_size = backtrace(array, 25); stacktrace_symbols = backtrace_symbols(array, stacktrace_size); #endif logwarning("%s raised: %s", class_name, message_text); } // ======================================================================== // Destructor // ======================================================================== TuscanyRuntimeException :: ~TuscanyRuntimeException() { if (class_name) delete class_name; if (message_text) delete message_text; for (int i=0;i1) { os << " Path:" << endl; int i=1; while (i < location_set) { os << " File: " << locations[i].file << endl; os << " Line: " << locations[i].line << endl; os << " Function: " << locations[i].function << endl; i++; } } } #if defined(WIN32) || defined (_WINDOWS) || defined (IS_DARWIN) #else if (stacktrace_size != 0) { os << " Backtrace:" << endl; for (int j = 0; j < stacktrace_size; j++) { os << " " << stacktrace_symbols[j] << endl; } } #endif return os; } // end ostream operator << // ======================================================================== // ostream operator << // ======================================================================== SCA_API ostream& operator<< (ostream &os, const TuscanyRuntimeException &except) { return except.PrintSelf(os); } // end ostream operator << } // End namespace sca } // End namespace tuscany