class Bag{ public: enum Error{WrongInput, EmptyBag}; struct Exception { Error message; int value; }; //... } void Bag::put(int e){ if (e<0 || e>n-1){ Exception ex; ex.message = WrongInput; ex.value = e; throw ex; } ++v[e]; if (v[e]> v[max]){ max = e; } } try{ ... h.put(x[i]); ... }catch(Bag::Exception ex){ if(ex.message == Bag::WrongInput){ cout << "A tömbbeli " << ex.value<< " nem 0 és 99 közé eső szám!\n"; } }