D
Daniel T.
This is basically what I have now...
class Foo { /* definition irrelevant */ };
istream& operator>>( istream& is, Foo& foo ); // could throw
int main() {
ifstream file( "file.txt" );
Foo foo;
int i = 0;
try {
while ( file >> foo ) {
//process foo;
++i;
}
}
catch ( exception& e ) {
cout << "error at: " << i << '\n';
}
}
The problem I'm having is that op>> could throw. If it does, I don't
want to process the foo object that threw, but I want the program to
report an error and continue extracting foo objects.
I could make op>> a no-throw and give Foo some sort of error or invalid
state, but that doesn't feel right. I can't report the error inside the
op>> because I don't have enough information to make a full report.
Does anyone have a better idea, or do I give Foo and error state and
query it after the read?
class Foo { /* definition irrelevant */ };
istream& operator>>( istream& is, Foo& foo ); // could throw
int main() {
ifstream file( "file.txt" );
Foo foo;
int i = 0;
try {
while ( file >> foo ) {
//process foo;
++i;
}
}
catch ( exception& e ) {
cout << "error at: " << i << '\n';
}
}
The problem I'm having is that op>> could throw. If it does, I don't
want to process the foo object that threw, but I want the program to
report an error and continue extracting foo objects.
I could make op>> a no-throw and give Foo some sort of error or invalid
state, but that doesn't feel right. I can't report the error inside the
op>> because I don't have enough information to make a full report.
Does anyone have a better idea, or do I give Foo and error state and
query it after the read?