Type mismatch during construction. More...
#include <tsExceptions.h>
Inherits tsException.
Public Member Functions | |
BadType (std::string nm, std::string type1, std::string type2) | |
void | debug_print () |
Type mismatch during construction.
Thrown when an attempt is made to construct a timeSeries object of one type from a data field containing another type. Implicit conversion in constructors is disallowed to ensure that the resulting memory and performance penalty does not occur without explicit authorization from the programmer. The same result can always be obtained by constructing a timeSeries object of the correct type and using an explicit conversion operator.
BadType::BadType | ( | std::string | nm, | |
std::string | type1, | |||
std::string | type2 | |||
) | [inline] |
nm | the name of the object | |
type1 | a string designating the type of timeSeries object | |
type2 | a string designating the type of the underlying data |
The information used to construct the BadType exception can be used by the debug_print method to generate readable error messages for the user
void BadType::debug_print | ( | ) | [inline, virtual] |
error message
If the data definition (as determined in the .hdr or .dfm file) for field EFFORT specifies a type of "float" then the following code will generate a BadType exception:
try { timeSeries<int> effort_int("EFFORT",data); } catch (tsException& tse) { tse.debug_print(); cerr << "skipping to next file..." << endl; }
Results in this error message:
Illegal Conversion: attempt to construct timeSeries object of type int from data field "EFFORT" of type float skipping to next file...
The same effect can be achieved explicitly without causing an exception:
timeSeries<float> effort_float("EFFORT",data); timeSeries<int> effort = timeSeries<int>(effort_float);
Reimplemented from tsException.