Gary Wessle wrote in message ...
>
does this include when a method calls another one in a composition
situation?
that is method A::a calls method B::b which Calls method C::c that
throws, can I catch and handle inside A::a? if yes, this is
amazing. can you give an example please?
thanks
ONLY because you said "please". <G>
// ------------------------------------
#include <iostream // #include <ostream>
#include <stdexcept>
#include <vector>
class Example{
public: // ------------------------------ public
void execute( std::ostream &cout ){
// ------------
cout<<"\n--- Exception test Bumfaddle ---"<<std::endl;
try{
BumFaddle Bf;
Bf.funcy( cout );
std::vector<intVint(2);
Vint.at(3); // out_of_range
} // try
catch( const std::out_of_range &Oor ){
cout<<"out_of_range caught: "<<Oor.what()<<std::endl;
}
catch( const std::exception &e ){ // Salt's example
cout<< "exception error: "<< e.what() <<std::endl;
}
// if you put "catch( out_of_range )" here, it will never get
// to it due to the 'higher-up' above.
catch( ... ){ // catch anything not caught above.
cout<<"caught something (maybe the flu!!)"<<std::endl;
}
cout<<"\n--- Exception test Bumfaddle ---end"<<std::endl;
// ------------
} // execute(ostream&)
// ------------------------------------
private: // ------------------------------ private
// ------------------------------------
class BumFaddle{ public:
void funcy( std::ostream &out){
try{ throw std::runtime_error("from funcy");}
catch( std::runtime_error &Re){
out<<"BumFaddle caught: "<<Re.what()<<std::endl;
throw; // send it on
}
} // funcy(ostream&)
}; // class BumFaddle
// ------------------------------------
}; // class Example
// ------------------------------------
int main(){
{
Example Ex;
Ex.execute( std::cout );
}
return 0;
} // main()
// ------------------------------------
Is that what you are after?
--
Bob R
POVrookie