Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
ArcaneException.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* ArcaneException.h (C) 2000-2025 */
9/* */
10/* Exceptions thrown by Arcane. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_ARCANEEXCEPTION_H
13#define ARCANE_CORE_ARCANEEXCEPTION_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Exception.h"
18#include "arcane/utils/String.h"
19
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31/*!
32 * \internal
33 * \brief Exception for an invalid identifier.
34 *
35 * This exception is thrown whenever an invalid identifier
36 * is used in the architecture.
37
38 The following rules must be respected for an identifier to be
39 valid:
40
41 \arg it must contain at least one character.
42 \arg it must start with an alphabetic character (a-zA-Z),
43 \arg it must be followed by a sequence of alphabetic characters, digits,
44 or the underscore character '_'.
45 */
46class ARCANE_CORE_EXPORT BadIDException
47: public Exception
48{
49 public:
50
51 /*!
52 * Constructs an exception related to the manager \a m, originating from the function
53 * \a where and with the invalid name \a invalid_name.
54 */
55 BadIDException(const String& where, const String& invalid_name);
56 ~BadIDException() ARCANE_NOEXCEPT override {}
57
58 public:
59
60 void explain(std::ostream& m) const override;
61
62 private:
63
64 String m_invalid_name; //!< Invalid identifier.
65};
66
67/*---------------------------------------------------------------------------*/
68/*---------------------------------------------------------------------------*/
69
70/*!
71 * \internal
72 * \brief Exception for an invalid entity ID.
73 *
74 * This exception is thrown whenever an entity ID (whether local or global)
75 * is invalid.
76 */
77class ARCANE_CORE_EXPORT BadItemIdException
78: public Exception
79{
80 public:
81
82 /*!
83 * \brief Constructs an exception.
84
85 Constructs an exception related to the message manager \a m,
86 originating from the function \a where and with the invalid ID \a id.
87 */
88 BadItemIdException(const String& where, Integer bad_id);
89 ~BadItemIdException() ARCANE_NOEXCEPT override {}
90
91 public:
92
93 void explain(std::ostream& m) const override;
94
95 private:
96
97 Integer m_bad_id; //!< Invalid ID.
98};
99
100/*---------------------------------------------------------------------------*/
101/*---------------------------------------------------------------------------*/
102
103/*!
104 * \internal
105 * \brief Exception when an internal error occurs.
106 */
107class ARCANE_CORE_EXPORT InternalErrorException
108: public Exception
109{
110 public:
111
112 InternalErrorException(const String& where, const String& why);
113 InternalErrorException(const TraceInfo& where, const String& why);
114 InternalErrorException(const InternalErrorException& ex) ARCANE_NOEXCEPT;
115 ~InternalErrorException() ARCANE_NOEXCEPT override {}
116
117 public:
118
119 void explain(std::ostream& m) const override;
120
121 private:
122
123 String m_why;
124};
125
126/*---------------------------------------------------------------------------*/
127/*---------------------------------------------------------------------------*/
128
129/*!
130 * \internal
131 * \brief Exception for an invalid variable kind/type.
132 *
133 * This exception is thrown when attempting to reference a variable
134 * that already exists in another module with a different kind or type.
135 */
136class ARCANE_CORE_EXPORT BadVariableKindTypeException
137: public Exception
138{
139 public:
140
141 BadVariableKindTypeException(const TraceInfo& where, IVariable* valid_var,
142 eItemKind kind, eDataType datatype, int dimension);
143 ~BadVariableKindTypeException() ARCANE_NOEXCEPT override {}
144
145 public:
146
147 void explain(std::ostream& m) const override;
148
149 private:
150
151 IVariable* m_valid_var;
152 eItemKind m_item_kind;
153 eDataType m_data_type;
154 int m_dimension;
155};
156
157/*---------------------------------------------------------------------------*/
158/*---------------------------------------------------------------------------*/
159
160/*!
161 * \internal
162 * \brief Exception for an invalid partial variable item group name.
163 *
164 * This exception is thrown when attempting to reference a partial variable
165 * that already exists in another module with a different item group name.
166 */
167class ARCANE_CORE_EXPORT BadPartialVariableItemGroupNameException
168: public Exception
169{
170 public:
171
172 BadPartialVariableItemGroupNameException(const TraceInfo& where, IVariable* valid_var,
173 const String& item_group_name);
174 ~BadPartialVariableItemGroupNameException() ARCANE_NOEXCEPT override {}
175
176 public:
177
178 void explain(std::ostream& m) const override;
179
180 private:
181
182 IVariable* m_valid_var;
183 String m_item_group_name;
184};
185
186/*---------------------------------------------------------------------------*/
187/*---------------------------------------------------------------------------*/
188
189/*!
190 * \internal
191 * \brief Exception when a mesh entity is not of a known type.
192 */
193class ARCANE_CORE_EXPORT UnknownItemTypeException
194: public Exception
195{
196 public:
197
198 UnknownItemTypeException(const String& where, Integer nb_node, Integer item_id);
199 UnknownItemTypeException(const UnknownItemTypeException& ex) ARCANE_NOEXCEPT;
200 ~UnknownItemTypeException() ARCANE_NOEXCEPT override {}
201
202 public:
203
204 void explain(std::ostream& m) const override;
205
206 private:
207
208 Integer m_nb_node;
209 Integer m_item_id;
210};
211
212/*---------------------------------------------------------------------------*/
213/*---------------------------------------------------------------------------*/
214
215/*!
216 * \internal
217 * \brief Exception when trying to dereference a null pointer.
218 */
219class ARCANE_CORE_EXPORT BadReferenceException
220: public Exception
221{
222 public:
223
224 explicit BadReferenceException(const String& where);
225 ~BadReferenceException() ARCANE_NOEXCEPT override {}
226
227 public:
228
229 void explain(std::ostream& m) const override;
230
231 private:
232};
233
234/*---------------------------------------------------------------------------*/
235/*---------------------------------------------------------------------------*/
236
237/*!
238 * \internal
239 * \brief Exception in a reader or writer.
240 */
241class ARCANE_CORE_EXPORT ReaderWriterException
242: public Exception
243{
244 public:
245
246 ReaderWriterException(const String& where, const String& message);
247 ReaderWriterException(const TraceInfo& where, const String& message);
248 ReaderWriterException(const ReaderWriterException& ex) ARCANE_NOEXCEPT;
249 ~ReaderWriterException() ARCANE_NOEXCEPT override {}
250
251 public:
252
253 void explain(std::ostream& m) const override;
254};
255
256/*---------------------------------------------------------------------------*/
257/*---------------------------------------------------------------------------*/
258
259/*!
260 * \internal
261 * \brief Exception in an assertion.
262 */
263class ARCANE_CORE_EXPORT AssertionException
264: public Exception
265{
266 public:
267
268 /*!
269 * Constructs an exception originating from the function \a where.
270 */
271 explicit AssertionException(const TraceInfo& where);
272
273 /*!
274 * Constructs an exception originating from the function \a where.
275 * The expected value in the assertion was \a expected, the obtained result was \a actual.
276 */
277 AssertionException(const TraceInfo& where, const String& expected, const String& actual);
278
279 public:
280
281 void explain(std::ostream& m) const override;
282
283 //! File of the exception
284 const char* file() const { return m_file; }
285
286 //! Line of the exception
287 int line() const { return m_line; }
288
289 public:
290
291 using Exception::message;
292 using Exception::where;
293
294 private:
295
296 const char* m_file;
297 int m_line;
298};
299
300/*---------------------------------------------------------------------------*/
301/*---------------------------------------------------------------------------*/
302
303} // End namespace Arcane
304
305/*---------------------------------------------------------------------------*/
306/*---------------------------------------------------------------------------*/
307
308#endif
Declarations of Arcane's general types.
const String & where() const
Location of the exception.
const char * file() const
File of the exception.
int line() const
Line of the exception.
void explain(std::ostream &m) const override
Explains the cause of the exception in the stream o.
AssertionException(const TraceInfo &where)
BadIDException(const String &where, const String &invalid_name)
void explain(std::ostream &m) const override
Explains the cause of the exception in the stream o.
BadItemIdException(const String &where, Integer bad_id)
Constructs an exception.
void explain(std::ostream &m) const override
Explains the cause of the exception in the stream o.
void explain(std::ostream &m) const override
Explains the cause of the exception in the stream o.
void explain(std::ostream &m) const override
Explains the cause of the exception in the stream o.
void explain(std::ostream &m) const override
Explains the cause of the exception in the stream o.
const String & where() const
Location of the exception.
const String & message() const
Exception message.
Exception(const String &name, const String &where)
Interface of a variable.
Definition IVariable.h:40
void explain(std::ostream &m) const override
Explains the cause of the exception in the stream o.
void explain(std::ostream &m) const override
Explains the cause of the exception in the stream o.
void explain(std::ostream &m) const override
Explains the cause of the exception in the stream o.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
eItemKind
Mesh entity type.
eDataType
Data type.
Definition DataTypes.h:41