CARLsim  6.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 }
parameter cannot have smaller vaule than some vaule
Definition: user_errors.h:38
parameter cannot be zero
Definition: user_errors.h:44
parameters must be identical
Definition: user_errors.h:50
#define CARLSIM_ERROR(where, what)
parameters cannot be identical
Definition: user_errors.h:34
could not open file
Definition: user_errors.h:46
parameter cannot be of type UNKNOWN
Definition: user_errors.h:43
could not create a file
Definition: user_errors.h:45
function cannot be called in certain mode
Definition: user_errors.h:30
errorType
an enum of all possible error codes
Definition: user_errors.h:26
function cannot be called in certain state
Definition: user_errors.h:31
function cannot be called because network has already bun run
Definition: user_errors.h:61
parameter cannot have larger vaule than some vaule
Definition: user_errors.h:37
some parameters must have the same sign
Definition: user_errors.h:60
the specified group id is unknown
Definition: user_errors.h:62
parameter must be set to
Definition: user_errors.h:56
deprecated function
Definition: user_errors.h:48
could not read file
Definition: user_errors.h:47
parameter cannot be set to
Definition: user_errors.h:42
parameter must be in some range
Definition: user_errors.h:51
parameter cannot have NULL value
Definition: user_errors.h:36
parameter must be off
Definition: user_errors.h:53
an unknown error
Definition: user_errors.h:63
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
function cannot be applied to neuron type
Definition: user_errors.h:64
parameter cannot be on
Definition: user_errors.h:40
parameter must be smaller than
Definition: user_errors.h:58
parameter cannot have positive value (opposite to "must be", but includes zero)
Definition: user_errors.h:41
parameter must be on
Definition: user_errors.h:54
parameter must be larger than
Definition: user_errors.h:57
function can only be called in certain state
Definition: user_errors.h:29
parameter cannot be off
Definition: user_errors.h:39
keyword ALL is not allowed for this variable
Definition: user_errors.h:27
cannot be connected twice
Definition: user_errors.h:33
cannot be both synaptically and compartmentally connected
Definition: user_errors.h:32
parameter must have negative value
Definition: user_errors.h:52
parameter must have positive value
Definition: user_errors.h:55
function can only be called in certain mode
Definition: user_errors.h:28
parameter cannot have negative value (opposite to "must be", but includes zero)
Definition: user_errors.h:35