cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cmnThrow.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5 
6  Author(s): Anton Deguet
7  Created on: 2005-09-22
8 
9  (C) Copyright 2005-2007 Johns Hopkins University (JHU), All Rights
10  Reserved.
11 
12 --- begin cisst license - do not edit ---
13 
14 This software is provided "as is" under an open source license, with
15 no warranty. The complete license can be found in license.txt and
16 http://www.cisst.org/cisst/license.txt.
17 
18 --- end cisst license ---
19 
20 */
21 
22 
27 #pragma once
28 
29 #ifndef _cmnThrow_h
30 #define _cmnThrow_h
31 
32 
33 #include <cisstCommon/cmnLogger.h>
34 
35 #include <stdexcept>
36 #include <cstdlib>
37 
75 template <class _exceptionType>
76 inline void cmnThrow(const _exceptionType & except, cmnLogLevel lod = CMN_LOG_LEVEL_INIT_ERROR) throw(_exceptionType) {
77  // try to create an std::exception pointer
78  const std::exception * stdExcept = dynamic_cast<const std::exception *>(&except);
79  if (stdExcept) {
80  CMN_LOG(lod) << "cmnThrow with std::exception ("
81  << stdExcept->what()
82  << ")"
83  << std::endl;
84  } else {
85  CMN_LOG(lod) << "cmnThrow with non std::exception"
86  << std::endl;
87  }
88 #ifdef CISST_CMN_THROW_DOES_ABORT
89  CMN_LOG(lod) << "cmnThrow is configured to abort() (CISST_CMN_THROW_DOES_ABORT defined)"
90  << std::endl;
91  std::abort();
92 #else
93  throw except;
94 #endif // CISST_CMN_THROW_DOES_ABORT
95 }
96 
97 
111 inline void cmnThrow(const std::string & message, cmnLogLevel lod = CMN_LOG_LEVEL_INIT_ERROR) throw(std::runtime_error) {
112  cmnThrow(std::runtime_error(message), lod);
113 }
114 
115 inline void cmnThrow(const char * message, cmnLogLevel lod = CMN_LOG_LEVEL_INIT_ERROR) throw(std::runtime_error) {
116  cmnThrow(std::runtime_error(std::string(message)), lod);
117 }
119 
120 
121 #endif // _cmnThrow_h
122 
#define CMN_LOG_LEVEL_INIT_ERROR
Definition: cmnLogLoD.h:58
void cmnThrow(const _exceptionType &except, cmnLogLevel lod=CMN_LOG_LEVEL_INIT_ERROR)
Definition: cmnThrow.h:76
short cmnLogLevel
Definition: cmnLogLoD.h:55
Declaration of cmnLogger amd macros for human readable logging.
#define CMN_LOG(lod)
Definition: cmnLogger.h:150