From: Andreas Huber (ahd6974-spamgroupstrap_at_[hidden])
Date: 2006-07-18 16:04:32


Jeremy Day wrote:
> However, I think that this technique, or some derivation thereof, can
> help make code more maintainable, since you can reuse
> my_exception_handler whenever you
> want to handle the same exception in the same way, even though you
> catch it in a different place.

How is your approach better than:

// Untested code
#include <stdexcept>

// Generic handler function
void HandleException()
{
  try
  {
    throw;
  }
  catch (const std::logic_error &)
  {
    // whatever
  }
  catch (const std::exception &)
  {
     // whatever
  }
}

int main()
{
  try
  {
    // throwing code
  }
  catch (...)
  {
    HandleException();
  }

  return 0;
}

?

Regards,

-- 
Andreas Huber
When replying by private email, please remove the words spam and trap
from the address shown in the header.