Commit c8fd4e45 authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

updating read of EOF in eafstream, to throw a logic_error instead of dumping...

updating read of EOF in eafstream, to throw a logic_error instead of dumping message and returning negative value.
parent 2c2ac653
Pipeline #7449 passed with stages
in 23 minutes and 25 seconds
......@@ -143,8 +143,10 @@ short eafstream::readShort()
if (this->bad() || this->eof())
{
std::cout << "Error, reading int from file at offset." << this->tellg() << std::endl;
return -1;
std::stringstream ss;
ss << "Error, reading short from file at offset." << this->tellg();
std::cout << ss.str() << std::endl;
throw std::logic_error(ss.str());
}
if (mReverseBytes == true)
......@@ -167,8 +169,10 @@ int eafstream::readInt()
if (this->bad() || this->eof())
{
std::cout << "Error, reading int from file at offset." << this->tellg() << std::endl;
return -1;
std::stringstream ss;
ss << "Error, reading int from file at offset." << this->tellg();
std::cout << ss.str() << std::endl;
throw std::logic_error(ss.str());
}
if (mReverseBytes == true)
......@@ -203,8 +207,10 @@ float eafstream::readFloat()
if (this->bad() || this->eof())
{
std::cerr << "Error, reading float from file at offset:" << this->tellg() << std::endl;
return -1.0;
std::stringstream ss;
ss << "Error, reading float from file at offset." << this->tellg();
std::cout << ss.str() << std::endl;
throw std::logic_error(ss.str());
}
if (mReverseBytes == true)
......@@ -228,8 +234,10 @@ double eafstream::readDouble()
if (this->bad() || this->eof())
{
std::cerr << "Error, reading double from file at offset:" << this->tellg() << std::endl;
return -1.0;
std::stringstream ss;
ss << "Error, reading double from file at offset." << this->tellg();
std::cout << ss.str() << std::endl;
throw std::logic_error(ss.str());
}
if (mReverseBytes == true)
......@@ -262,10 +270,11 @@ int* eafstream::readIntArray(int size)
this->read((char*) (array), size * int_size);
if (this->bad() || this->eof())
{
std::cerr << "Error, cannot read the int array from file at offset:" << this->tellg() << std::endl;
std::stringstream ss;
ss << "Error, cannot read the int array from file at offset:" << this->tellg();
std::cerr << ss.str() << std::endl;
delete [] array;
array = NULL;
return NULL;
throw std::logic_error(ss.str());
}
if (mReverseBytes == true)
{
......@@ -295,9 +304,11 @@ float* eafstream::readFloatArray(int size)
this->read((char*) (array), size * float_size);
if (this->bad() || this->eof())
{
std::cerr << "Error, cannot read the int array from file at offset:" << this->tellg() << std::endl;
array = NULL;
return NULL;
std::stringstream ss;
ss << "Error, cannot read the float array from file at offset:" << this->tellg();
std::cerr << ss.str() << std::endl;
delete [] array;
throw std::logic_error(ss.str());
}
if (mReverseBytes == true)
{
......@@ -327,9 +338,11 @@ double* eafstream::readDoubleArray(int size)
this->read((char*) (array), size * double_size);
if (this->bad() || this->eof())
{
std::cerr << "Error, cannot read the double array from file" << ((this->bad() != false) ? "- this->bad()" : "- this->eof()") << std::endl;
array = NULL;
return NULL;
std::stringstream ss;
ss << "Error, cannot read the double array from file at offset:" << this->tellg();
std::cerr << ss.str() << std::endl;
delete [] array;
throw std::logic_error(ss.str());
}
if (mReverseBytes == true)
{
......@@ -351,9 +364,11 @@ std::string eafstream::readString(int size)
array[size] = '\0';
if (this->bad() || this->eof())
{
std::cerr << "Error, cannot read the string from file" << ((this->bad() != false) ? "- this->bad()" : "- this->eof()") << std::endl;
delete[] array;
return NULL;
std::stringstream ss;
ss << "Error, cannot read the string from file" << ((this->bad() != false) ? "- this->bad()" : "- this->eof()") ;
std::cerr << ss.str() << std::endl;
delete [] array;
throw std::logic_error(ss.str());
}
//increment bytes read
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment