Throw exception if mode is not correct
When compiling with sanitized the static_cast does not result in a runtime_exception. Fixing it by throwing it explicitly.
When compiling with sanitized the static_cast does not result in a runtime_exception. Fixing it by throwing it explicitly.