Skip to content

Commit 7526cd8

Browse files
committed
class CColorAmount
The size should not be over 1 when calling Color and Value
1 parent bae76fc commit 7526cd8

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/amount.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "serialize.h"
1010

1111
#include <iostream>
12+
#include <stdexcept>
1213
#include <stdlib.h>
1314
#include <string>
1415

@@ -286,20 +287,18 @@ class CColorAmount : public colorAmount_t
286287

287288
type_Color Color() const
288289
{
289-
if (this->size() == 1)
290-
return this->begin()->first;
291-
else
292-
return -1;
290+
if (this->size() != 1)
291+
throw std::runtime_error("CColorAmount::Color(): The size of color amount should be 1.");
292+
return this->begin()->first;
293293
}
294294

295295
CAmount Value() const
296296
{
297-
if (this->size() == 1)
298-
return this->begin()->second;
299-
else if (this->size() == 0)
297+
if (this->size() == 0)
300298
return 0;
301-
else
302-
return -1;
299+
if (this->size() != 1)
300+
throw std::runtime_error("CColorAmount::Value(): The size of color amount should be 0 or 1.");
301+
return this->begin()->second;
303302
}
304303

305304
CAmount TotalValue() const

0 commit comments

Comments
 (0)