3

My company uses a this piece of code to delete ALL objects from memory.
But because of the catch(...) I wonder what happens if the destructor of that object fails (AV)? Is it ok to catch everything silently? If the destructor failed, don't we want to know about this?

#define DELNULL(p) \
{                  \
if (p)             \
   {               \
   try             \
      {delete p;}  \
   catch (...)     \
      {}           \
   p = NULL;       \
   }               \
}                  \
Gabriel
  • 20,797
  • 27
  • 159
  • 293

1 Answers1

1

Is it ok to catch everything silently?

It is generally not OK to silently catch everything (it's rarely OK to silently catch anything). It would be often useful to know about errors.

In some cases it may be better to not let exceptions propagate. For example, if we are in a function called from C, or if we don't want to terminate, and are in destructor or in a noexcept function. But, it would be better to fall back to some other form of error reporting rather than swallowing them silently.

P.S. if (p) check is redundant and can be safely removed.

eerorika
  • 232,697
  • 12
  • 197
  • 326