Arcane  v3.14.10.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
InvalidArgumentException.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 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/* InvalidArgumentException.cc (C) 2000-2018 */
9/* */
10/* Exception lorsqu'un argument est invalide. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/ArcanePrecomp.h"
15
16#include "arcane/utils/Iostream.h"
17#include "arcane/utils/InvalidArgumentException.h"
18#include "arcane/utils/OStringStream.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23ARCANE_BEGIN_NAMESPACE
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28InvalidArgumentException::
29InvalidArgumentException(const TraceInfo& where,const String& arg_name,
30 int arg_value)
31: Exception("InvalidArgument",where)
32, m_arg_name(arg_name)
33{
34 _init(arg_value);
35}
36
37/*---------------------------------------------------------------------------*/
38/*---------------------------------------------------------------------------*/
39
40InvalidArgumentException::
41InvalidArgumentException(const TraceInfo& where,const String& arg_name,
42 double arg_value)
43: Exception("InvalidArgument",where)
44, m_arg_name(arg_name)
45{
46 _init(arg_value);
47}
48
49/*---------------------------------------------------------------------------*/
50/*---------------------------------------------------------------------------*/
51
52InvalidArgumentException::
53InvalidArgumentException(const TraceInfo& where,const String& arg_name,
54 const String& arg_value)
55: Exception("InvalidArgument",where)
56, m_arg_name(arg_name)
57{
58 _init(arg_value);
59}
60
61/*---------------------------------------------------------------------------*/
62/*---------------------------------------------------------------------------*/
63
64InvalidArgumentException::
65InvalidArgumentException(const TraceInfo& where,const String& arg_name,
66 const void* arg_value)
67: Exception("InvalidArgument",where)
68, m_arg_name(arg_name)
69{
70 _init(arg_value);
71}
72
73/*---------------------------------------------------------------------------*/
74/*---------------------------------------------------------------------------*/
75
76InvalidArgumentException::
77InvalidArgumentException(const TraceInfo& where,const String& arg_name,
78 const String& message,
79 int arg_value)
80: Exception("InvalidArgument",where)
81, m_arg_name(arg_name)
82, m_message(message)
83{
84 _init(arg_value);
85}
86
87/*---------------------------------------------------------------------------*/
88/*---------------------------------------------------------------------------*/
89
90InvalidArgumentException::
91InvalidArgumentException(const TraceInfo& where,const String& arg_name,
92 const String& message,
93 double arg_value)
94: Exception("InvalidArgument",where)
95, m_arg_name(arg_name)
96, m_message(message)
97{
98 _init(arg_value);
99}
100
101/*---------------------------------------------------------------------------*/
102/*---------------------------------------------------------------------------*/
103
104InvalidArgumentException::
105InvalidArgumentException(const TraceInfo& where,const String& arg_name,
106 const String& message,
107 const String& arg_value)
108: Exception("InvalidArgument",where)
109, m_arg_name(arg_name)
110, m_message(message)
111{
112 _init(arg_value);
113}
114
115/*---------------------------------------------------------------------------*/
116/*---------------------------------------------------------------------------*/
117
118InvalidArgumentException::
119InvalidArgumentException(const TraceInfo& where,const String& arg_name,
120 const String& message,
121 const void* arg_value)
122: Exception("InvalidArgument",where)
123, m_arg_name(arg_name)
124, m_message(message)
125{
126 _init(arg_value);
127}
128
129/*---------------------------------------------------------------------------*/
130/*---------------------------------------------------------------------------*/
131
132InvalidArgumentException::
133InvalidArgumentException(const InvalidArgumentException& ex)
134: Exception(ex)
135, m_arg_name(ex.m_arg_name)
136, m_arg_value(ex.m_arg_value)
137, m_message(ex.m_message)
138{
139}
140
141/*---------------------------------------------------------------------------*/
142/*---------------------------------------------------------------------------*/
143
144template<typename U> void InvalidArgumentException::
145_init(const U& arg_value)
146{
147 OStringStream ostr;
148 ostr() << arg_value;
149 m_arg_value = ostr.str();
150}
151
152
153/*---------------------------------------------------------------------------*/
154/*---------------------------------------------------------------------------*/
155
156void InvalidArgumentException::
157explain(std::ostream& m) const
158{
159 m << "Argument invalide: nom='" << m_arg_name
160 << "' valeur='" << m_arg_value << "'.";
161 if (!m_message.null())
162 m << m_message << ".";
163 m << "\n";
164}
165
166/*---------------------------------------------------------------------------*/
167/*---------------------------------------------------------------------------*/
168
169ARCANE_END_NAMESPACE
170
171/*---------------------------------------------------------------------------*/
172/*---------------------------------------------------------------------------*/