forked from micro-manager/micro-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Error.cpp
117 lines (94 loc) · 3 KB
/
Error.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
///////////////////////////////////////////////////////////////////////////////
// PROJECT: Micro-Manager
// SUBSYSTEM: MMCore
//-----------------------------------------------------------------------------
// DESCRIPTION: Exception class for core errors
//
// COPYRIGHT: University of California, San Francisco, 2006,
// All Rights reserved
//
// LICENSE: This file is distributed under the "Lesser GPL" (LGPL) license.
// License text is included with the source distribution.
//
// This file is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES.
//
// AUTHOR: Nenad Amodaj (original header-only version)
// Mark Tsuchida, 12/04/2013 (made chainable)
//
// NOTE: API documentation is in the header file.
#include "Error.h"
CMMError::CMMError(const std::string& msg, Code code) :
message_(msg),
code_(code),
underlying_(0)
{}
CMMError::CMMError(const char* msg, Code code) :
message_(msg ? msg : "(null message)"),
code_(code),
underlying_(0)
{}
CMMError::CMMError(const std::string& msg, Code code, const CMMError& underlyingError) :
message_(msg),
code_(code),
underlying_(new CMMError(underlyingError))
{}
CMMError::CMMError(const char* msg, Code code, const CMMError& underlyingError) :
message_(msg ? msg : "(null message)"),
code_(code),
underlying_(new CMMError(underlyingError))
{}
CMMError::CMMError(const std::string& msg, const CMMError& underlyingError) :
message_(msg),
code_(MMERR_GENERIC),
underlying_(new CMMError(underlyingError))
{}
CMMError::CMMError(const char* msg, const CMMError& underlyingError) :
message_(msg ? msg : "(null message)"),
code_(MMERR_GENERIC),
underlying_(new CMMError(underlyingError))
{}
CMMError::CMMError(const CMMError& other) :
message_(other.message_),
code_(other.code_),
underlying_(0)
{
if (other.getUnderlyingError())
underlying_.reset(new CMMError(*(other.getUnderlyingError())));
}
std::string
CMMError::getMsg() const
{
if (message_.empty())
return "Error (code " + boost::lexical_cast<std::string>(code_) + ")";
return message_;
}
std::string
CMMError::getFullMsg() const
{
if (getUnderlyingError())
return getMsg() + " [ " + underlying_->getFullMsg() + " ]";
return getMsg();
}
CMMError::Code
CMMError::getSpecificCode() const
{
if (code_ == MMERR_OK || code_ == MMERR_GENERIC)
{
if (getUnderlyingError())
return getUnderlyingError()->getSpecificCode();
else
return MMERR_GENERIC;
}
return code_;
}
const CMMError*
CMMError::getUnderlyingError() const
{
return underlying_.get();
}