/**
*
* \file TestFailure.cpp
*
* \author D. Mathieu, M. Laporte
*
* \date 10/02/2011
*
**/
#include <iostream>
#include "CstCodErr.h"
#include "CException.h"
using namespace std;
using namespace nsUtil;
namespace
{
void testFailure (void)
{
cout << "testFailure\n\n";
cin.exceptions (ios_base::failbit | ios_base::eofbit);
try
{
int i;
for (;;)
{
cout << "Un entier : ";
cin >> i;
}
}
catch (const ios_base::failure & exc)
{
if (cin.eof ()) cerr << "Fin de fichier\n";
else if (cin.fail ()) cerr << "Erreur de lecture\n";
cerr << exc.what () << '\n';
throw;
}
} // testFailure()
} // namespace
int main (void)
{
try
{
testFailure ();
return KNoExc;
}
catch (const CException & e)
{
cerr << "Erreur : " << e.getLibelle () << '\n'
<< "Code d'erreur = " << e.getCodErr () << '\n';
return e.getCodErr ();
}
catch (const exception & e)
{
cerr << "Exception standard : " << e.what () << '\n';
return KExcStd;
}
catch (...)
{
cerr << "Exception inconnue\n";
return KExcInconnue;
}
} // main()