#include <iostream>
#include "chiffre.h"
#include "paschiffreexception.h"
using namespace std;

int main()
{

    try{
        chiffre mon_chiffre(12);
        mon_chiffre.toString();

    }catch(PasChiffreException ecp1){
        cout<<"La valeur entré n&#039;est pas un chiffre"<<endl;
    }


    return 0;
}
//--------------------------------------------------------------------------------------------------------
#ifndef CHIFFRE_H
#define CHIFFRE_H


class chiffre
{
public:
    chiffre(int ent);
    void toString();
private:
    int entier;
};

#endif // CHIFFRE_H
//--------------------------------------------------------------------------------------------------------
#ifndef PASCHIFFREEXCEPTION_H
#define PASCHIFFREEXCEPTION_H
#include <stdexcept>
using namespace std;
class PasChiffreException : public exception{
public:
    PasChiffreException();
};

#endif // PASCHIFFREEXCEPTION_H
//--------------------------------------------------------------------------------------------------------
#include "chiffre.h"
#include "paschiffreexception.h"
#include <iostream>
using namespace std;
chiffre::chiffre(int ent)
{
    cout<<"L&#039;entier est : "<<ent<<endl;
    if(ent<0 || ent >9){
        throw PasChiffreException();
    }
    this->entier=ent;
}

void chiffre::toString(){
    cout<<"L&#039;entier est : "<<this->entier<<endl;
}
//--------------------------------------------------------------------------------------------------------
#include "paschiffreexception.h"
#include <stdexcept>
#include <iostream>
using namespace std;

PasChiffreException::PasChiffreException()
{
    cout<<"La classe excpetion PasChiffreException est appellé !"<<endl;
}

Add a code snippet to your website: www.paste.org