Bonjour
J'essaie de definir mes propres exceptions. Pour celà, j'ai un fichier .h :
Code:
#ifndef EXCEPTION_H
#define EXCEPTION_H
#include <string>
#include <conio.h>
using namespace std;
class StandardException : public exception
{
protected :
string msg;
public:
StandardException() throw();
StandardException(const exception&) throw();
StandardException& operator=(const StandardException&) throw();
StandardException(string msgerr) throw();
virtual ~StandardException() throw();
virtual const char* what(void) const throw();
};
class InFileException : public StandardException
{
public:
InFileException(string);
};
class OutFileException : public StandardException
{
public:
OutFileException(string);
};
class MenuChoiceException : public StandardException
{
public:
MenuChoiceException(string);
};
#endif
Avec le fichier .cpp associe :
Code:
#include <string>
#include <conio.h>
#include "Exceptions.h"
using namespace std;
StandardException::StandardException()
{
// msg="\nUne Exception a ete soulevee.\n";
}
StandardException::StandardException(string msgerr)
{
msg=msgerr;
}
string StandardException::what()
{
return(msg);
}
InFileException::InFileException(string msgerr)
{
msg="Une erreur s'est produite a l'ouverture du fichier de donnees.\n";
msg+="Verifiez l'existence des fichiers passes en parametre et reessayez.\n";
msg+="Si le probleme persiste, contactez l'Administrateur.\n\n";
}
...
A la compilation, j'obtiens :
Code:
Exceptions.cpp:8: declaration of `StandardException::StandardException()'
throws different exceptions
Exceptions.h:15: than previous declaration `
StandardException::StandardException() throw ()'
Exceptions.cpp:13: declaration of `
StandardException::StandardException(std::basic_string<char,
std::char_traits<char>, std::allocator<char> >)' throws different exceptions
Exceptions.h:18: than previous declaration `
StandardException::StandardException(std::basic_string<char,
std::char_traits<char>, std::allocator<char> >) throw ()'
Exceptions.cpp:18: prototype for `std::string StandardException::what()' does
not match any in class `StandardException'
Exceptions.h:20: candidate is: virtual const char* StandardException::what()
const
Que manque-t-il ?
Merci