exception.h
3.63 KB
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
/*
* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of NVIDIA CORPORATION nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <stdexcept>
#include <string>
namespace nvidia {
namespace aiaa {
/*!
@brief exception indicating a parse error
This exception is thrown by the library when error occurs. These errors
can occur during the deserialization of JSON text, CURL, as well
as when using invalid Arguments.
Exceptions have ids 1xx.
name / id | description
------------------------------ | -------------------------
nvidia.aiaa.error.101 | Failed to communicate to AIAA Server.
nvidia.aiaa.error.102 | Failed to parse AIAA Server Response.
nvidia.aiaa.error.103 | Failed to process ITK Operations.
nvidia.aiaa.error.104 | Invalid Arguments.
nvidia.aiaa.error.105 | AIAA Session Timeout.
nvidia.aiaa.error.106 | AIAA Response Error.
nvidia.aiaa.error.107 | System/Unknown Error.
*/
class exception : public std::exception {
public:
/// @brief Enum for Error Type
enum errorType {
AIAA_SERVER_ERROR = 101, ///Failed to communicate to AIAA Server
RESPONSE_PARSE_ERROR = 102, /// Failed to parse AIAA Server Response
ITK_PROCESS_ERROR = 103, /// Failed to process ITK Operations
INVALID_ARGS_ERROR = 104, /// Invalid Arguments
AIAA_SESSION_TIMEOUT = 105, /// AIAA Session Timeout,
AIAA_RESPONSE_ERROR = 106, /// AIAA Response Error
SYSTEM_ERROR = 107, /// System/Unknown Error
};
/// Message String for each enum type
const std::string messages[7] = { "Failed to communicate to AIAA Server", "Failed to parse AIAA Server Response",
"Failed to process ITK Operations", "Invalid Arguments", "AIAA Session Timeout", "AIAA Response Error", "System/Unknown Error" };
/// returns the explanatory string
const char* what() const noexcept override {
return m.what();
}
/// the id of the exception
errorType id = SYSTEM_ERROR;
/// Construct exception
exception(errorType id_, const char *what_arg)
:
id(id_),
m(what_arg) {
}
/// String version of error
std::string name() const {
return messages[id - AIAA_SERVER_ERROR];
}
private:
/// an exception object as storage for error messages
std::runtime_error m;
};
}
}