CARLsim  4.1.0
CARLsim: a GPU-accelerated SNN simulator
user_errors.cpp
Go to the documentation of this file.
1 #include <user_errors.h>
2 
3 #include <carlsim_definitions.h>
4 
5 #include <stdio.h>
6 #include <iostream> // std::cerr, std::cerr, std::endl
7 #include <stdlib.h> // exit, EXIT_FAILURE
8 #include <string> // std::string
9 
13 
14 // simple wrapper to assert a statement and print an error message
15 void UserErrors::assertTrue(bool statement, errorType errorIfAssertionFails, std::string errorFunc,
16  std::string errorMsgPrefix, std::string errorMsgSuffix) {
17  if (!statement) {
18  throwError(errorFunc,errorIfAssertionFails,errorMsgPrefix,errorMsgSuffix); // display standard error message
19  }
20 }
21 
22 
26 
27 // simple wrapper for displaying standard message per error type
28 void UserErrors::throwError(std::string errorFunc, errorType error, std::string errorMsgPrefix,
29  std::string errorMsgSuffix) {
30 
31  std::string errorMsg = errorMsgPrefix;
32 
33 // std::cerr << "\033[31;1m[USER ERROR " << errorFunc << "] \033[0m" << errorMsgPrefix;
34  switch (error) {
35  case ALL_NOT_ALLOWED:
36  errorMsg += " cannot be ALL."; break;
38  errorMsg += " can only be called in mode "; break;
40  errorMsg += " can only be called in state "; break;
42  errorMsg += " cannot be called in mode "; break;
44  errorMsg += " cannot be called in state "; break;
46  errorMsg += " cannot be both synaptically and compartmentally connected."; break;
48  errorMsg += " connectCompartments is bidirectional: connecting same groups twice is illegal "; break;
50  errorMsg += " cannot be identical."; break;
51  case CANNOT_BE_LARGER:
52  errorMsg += " cannot be larger than "; break;
53  case CANNOT_BE_NEGATIVE:
54  errorMsg += " cannot be negative."; break;
55  case CANNOT_BE_NULL:
56  errorMsg += " cannot be NULL."; break;
57  case CANNOT_BE_POSITIVE:
58  errorMsg += " cannot be positive."; break;
59  case CANNOT_BE_OFF:
60  errorMsg += " cannot not be off at this point."; break;
61  case CANNOT_BE_ON:
62  errorMsg += " cannot be on at this point."; break;
63  case CANNOT_BE_SET_TO:
64  errorMsg += " cannot be set to "; break;
65  case CANNOT_BE_SMALLER:
66  errorMsg += " cannot be smaller than "; break;
67  case CANNOT_BE_UNKNOWN:
68  errorMsg += " cannot be of type UNKNOWN."; break;
69  case CANNOT_BE_ZERO:
70  errorMsg += " cannot be zero."; break;
71  case FILE_CANNOT_CREATE:
72  errorMsg += " could not be created."; break;
73  case FILE_CANNOT_OPEN:
74  errorMsg += " could not be opened."; break;
75  case FILE_CANNOT_READ:
76  errorMsg += " could not be read."; break;
77  case IS_DEPRECATED:
78  errorMsg += " is deprecated."; break;
79  case MUST_BE_IDENTICAL:
80  errorMsg += " must be identical."; break;
81  case MUST_BE_LARGER:
82  errorMsg += " must be larger than "; break;
83  case MUST_BE_NEGATIVE:
84  errorMsg += " must be negative."; break;
85  case MUST_BE_POSITIVE:
86  errorMsg += " must be positive."; break;
87  case MUST_BE_OFF:
88  errorMsg += " must be off at this point."; break;
89  case MUST_BE_ON:
90  errorMsg += " must be on at this point."; break;
91  case MUST_BE_IN_RANGE:
92  errorMsg += " must be in the range "; break;
93  case MUST_BE_SET_TO:
94  errorMsg += " must be set to "; break;
95  case MUST_BE_SMALLER:
96  errorMsg += " must be smaller than "; break;
98  errorMsg += " must have the same sign."; break;
100  errorMsg += " cannot be called after network has been run."; break;
101  case UNKNOWN_GROUP_ID:
102  errorMsg += " is unknown."; break;
103  case WRONG_NEURON_TYPE:
104  errorMsg += " cannot be called on this neuron type."; break;
105  case UNKNOWN:
106  default:
107  errorMsg += ". An unknown error has occurred."; break;
108  }
109  errorMsg += errorMsgSuffix;
110 
111  CARLSIM_ERROR(errorFunc.c_str(), errorMsg.c_str());
112  exit(EXIT_FAILURE); // abort
113 }
CARLSIM_ERROR
#define CARLSIM_ERROR(where, what)
Definition: carlsim_definitions.h:83
UserErrors::CANNOT_BE_OFF
@ CANNOT_BE_OFF
parameter cannot be off
Definition: user_errors.h:37
UserErrors::CANNOT_BE_LARGER
@ CANNOT_BE_LARGER
parameter cannot have larger vaule than some vaule
Definition: user_errors.h:35
UserErrors::CANNOT_BE_SET_TO
@ CANNOT_BE_SET_TO
parameter cannot be set to
Definition: user_errors.h:40
UserErrors::CANNOT_BE_POSITIVE
@ CANNOT_BE_POSITIVE
parameter cannot have positive value (opposite to "must be", but includes zero)
Definition: user_errors.h:39
UserErrors::CANNOT_BE_IDENTICAL
@ CANNOT_BE_IDENTICAL
parameters cannot be identical
Definition: user_errors.h:32
UserErrors::CANNOT_BE_ON
@ CANNOT_BE_ON
parameter cannot be on
Definition: user_errors.h:38
UserErrors::MUST_BE_SMALLER
@ MUST_BE_SMALLER
parameter must be smaller than
Definition: user_errors.h:56
user_errors.h
UserErrors::MUST_BE_IDENTICAL
@ MUST_BE_IDENTICAL
parameters must be identical
Definition: user_errors.h:48
UserErrors::UNKNOWN_GROUP_ID
@ UNKNOWN_GROUP_ID
the specified group id is unknown
Definition: user_errors.h:60
UserErrors::CAN_ONLY_BE_CALLED_IN_STATE
@ CAN_ONLY_BE_CALLED_IN_STATE
function can only be called in certain state
Definition: user_errors.h:27
UserErrors::MUST_BE_POSITIVE
@ MUST_BE_POSITIVE
parameter must have positive value
Definition: user_errors.h:53
UserErrors::NETWORK_ALREADY_RUN
@ NETWORK_ALREADY_RUN
function cannot be called because network has already bun run
Definition: user_errors.h:59
UserErrors::CANNOT_BE_CALLED_IN_STATE
@ CANNOT_BE_CALLED_IN_STATE
function cannot be called in certain state
Definition: user_errors.h:29
UserErrors::MUST_BE_ON
@ MUST_BE_ON
parameter must be on
Definition: user_errors.h:52
UserErrors::FILE_CANNOT_CREATE
@ FILE_CANNOT_CREATE
could not create a file
Definition: user_errors.h:43
UserErrors::MUST_BE_IN_RANGE
@ MUST_BE_IN_RANGE
parameter must be in some range
Definition: user_errors.h:49
UserErrors::CANNOT_BE_NULL
@ CANNOT_BE_NULL
parameter cannot have NULL value
Definition: user_errors.h:34
UserErrors::FILE_CANNOT_OPEN
@ FILE_CANNOT_OPEN
could not open file
Definition: user_errors.h:44
UserErrors::CANNOT_BE_CONN_TWICE
@ CANNOT_BE_CONN_TWICE
cannot be connected twice
Definition: user_errors.h:31
UserErrors::IS_DEPRECATED
@ IS_DEPRECATED
deprecated function
Definition: user_errors.h:46
UserErrors::WRONG_NEURON_TYPE
@ WRONG_NEURON_TYPE
function cannot be applied to neuron type
Definition: user_errors.h:62
UserErrors::MUST_BE_LARGER
@ MUST_BE_LARGER
parameter must be larger than
Definition: user_errors.h:55
UserErrors::CANNOT_BE_CALLED_IN_MODE
@ CANNOT_BE_CALLED_IN_MODE
function cannot be called in certain mode
Definition: user_errors.h:28
UserErrors::MUST_BE_OFF
@ MUST_BE_OFF
parameter must be off
Definition: user_errors.h:51
UserErrors::CAN_ONLY_BE_CALLED_IN_MODE
@ CAN_ONLY_BE_CALLED_IN_MODE
function can only be called in certain mode
Definition: user_errors.h:26
UserErrors::UNKNOWN
@ UNKNOWN
an unknown error
Definition: user_errors.h:61
UserErrors::errorType
errorType
an enum of all possible error codes
Definition: user_errors.h:24
UserErrors::CANNOT_BE_UNKNOWN
@ CANNOT_BE_UNKNOWN
parameter cannot be of type UNKNOWN
Definition: user_errors.h:41
UserErrors::FILE_CANNOT_READ
@ FILE_CANNOT_READ
could not read file
Definition: user_errors.h:45
UserErrors::CANNOT_BE_ZERO
@ CANNOT_BE_ZERO
parameter cannot be zero
Definition: user_errors.h:42
UserErrors::MUST_BE_NEGATIVE
@ MUST_BE_NEGATIVE
parameter must have negative value
Definition: user_errors.h:50
UserErrors::MUST_BE_SET_TO
@ MUST_BE_SET_TO
parameter must be set to
Definition: user_errors.h:54
UserErrors::MUST_HAVE_SAME_SIGN
@ MUST_HAVE_SAME_SIGN
some parameters must have the same sign
Definition: user_errors.h:58
UserErrors::assertTrue
static void assertTrue(bool statement, errorType errorIfAssertionFails, std::string errorFunc, std::string errorMsgPrefix="", std::string errorMsgSuffix="")
simple wrapper for assert statement
Definition: user_errors.cpp:15
UserErrors::CANNOT_BE_NEGATIVE
@ CANNOT_BE_NEGATIVE
parameter cannot have negative value (opposite to "must be", but includes zero)
Definition: user_errors.h:33
UserErrors::CANNOT_BE_CONN_SYN_AND_COMP
@ CANNOT_BE_CONN_SYN_AND_COMP
cannot be both synaptically and compartmentally connected
Definition: user_errors.h:30
UserErrors::ALL_NOT_ALLOWED
@ ALL_NOT_ALLOWED
keyword ALL is not allowed for this variable
Definition: user_errors.h:25
UserErrors::CANNOT_BE_SMALLER
@ CANNOT_BE_SMALLER
parameter cannot have smaller vaule than some vaule
Definition: user_errors.h:36
carlsim_definitions.h