[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
C++ exceptions in persistent streams
From: |
erik_ohrnberger |
Subject: |
C++ exceptions in persistent streams |
Date: |
Mon, 9 Jan 2006 13:34:24 -0500 |
Hi all,
I was just wondering if someone could point me in the right
direction for using C++ exception to capture any issues that the C++
persistence engine has reading or writing from/to archive streams.
I've created a sample program (see below) to test this without
success (I always get an "Aborted (core dumped)" error message. Please note
that the file "testfile.ost" does not exist, and this is the condition that
I want to 'catch'. I'd also want to catch any read or write issues to the
persistent stream, such as hard disk full, or a mal-formatted persistent
stream.
I'm fairly sure that exceptions are being used in the
commoncpp2-1.3.1 library, as I compiled the engine.cpp source file with the
-E g++ option, which emits the post-preprocessor code, and I see that all
the Engine operators have the "throw(Engine::Exception);" as part of their
declaration.
Any help would be greatly appreciated,
Erik.
================== Test Source code below
#include <iostream>
#include <string>
#include <cc++/persist.h>
using namespace std;
using namespace ost;
class PersistObj : public ost::BaseObject
{
public:
PersistObj( void ) { };
virtual ~PersistObj( void ) { };
// Persistence protocol
virtual bool write(
ost::Engine& archive ) const;
virtual bool read(
ost::Engine& archive );
std::string str1;
bool boolean1;
};
bool PersistObj::write( ost::Engine& archive ) const
{
archive
<< str1
<< boolean1
;
return true;
}
bool PersistObj::read( ost::Engine& archive )
{
archive
>> str1
>> boolean1
;
return true;
}
int main( int argc, char** argv )
{
const char* filename = "testfile.ost";
cout << "In main.\n";
try
{
cout << "In try block, calling MyFunc().\n";
fstream inputArchive( filename, ios::in | ios::binary );
Engine inputEngine( inputArchive, Engine::modeRead );
PersistObj* m = new PersistObj();
inputEngine >> *m;
inputArchive.close();
}
catch( Engine::Exception e )
{
cout << "Engine::Exception caught! " << e.getString() <<
endl;
}
catch( PersistException e )
{
cout << "PersistException caught! " << e.getString() <<
endl;
}
catch( ost::Exception e )
{
cout << "Caught ost::Exception" << e.getString() << endl;
}
catch( exception e )
{
cout << "Caught std::exception" << endl;
}
catch( char *str )
{
cout << "Caught some other exception: " << str << "\n";
}
cout << "Back in main. Execution resumes here.\n";
return 0;
}
- C++ exceptions in persistent streams,
erik_ohrnberger <=