Can static_cast throw an exception in C++?

Viewed 16091

Is it safe to assume that static_cast will never throw an exception?

For an int to Enum cast, an exception is not thrown even if it is invalid. Can I rely on this behavior? This following code works.

enum animal {
  CAT = 1,
  DOG = 2
};

int y = 10;
animal x = static_cast<animal>(y);
4 Answers
Related