Check out the Boost.Exception library, or rather, this page in the paragraph titled Adding arbitrary data to active exception objects :
void parse_file( char const * file_name )
{
boost::shared_ptr<FILE> f = file_open(file_name,"rb");
assert(f);
try
{
char buf[1024];
file_read( f.get(), buf, sizeof(buf) );
}
catch(boost::exception & e )
{
e << boost::errinfo_file_name(file_name);
throw;
}
}
Personally, I find the technique quite effective. Change the exception (adding context) and rethrow.
Java, ++ , , , , , .