Examples of errors detected by the V746 diagnostic

V746. Type slicing. An exception should be caught by reference rather than by value.


Oracle VM Virtual Box

V746 Type slicing. An exception should be caught by reference rather than by value. extpackutil.cpp 257


RTCString *VBoxExtPackLoadDesc(....)
{
  ....
  xml::XmlFileParser  Parser;
  try
  {
    Parser.read(szFilePath, Doc);
  }
  catch (xml::XmlError Err) // <=
  {
    return new RTCString(Err.what());
  }
  ....
}

Identical errors can be found in some other places:

  • V746 Type slicing. An exception should be caught by reference rather than by value. extpackutil.cpp 330

OpenToonz

V746 Type slicing. An exception should be caught by reference rather than by value. iocommand.cpp 1620


bool IoCmd::saveLevel(....)
{
  ....
  try {
    sl->save(fp, TFilePath(), overwritePalette);
  } catch (TSystemException se) { // <=
    QApplication::restoreOverrideCursor();
    MsgBox(WARNING, QString::fromStdWString(se.getMessage()));
    return false;
  } catch (...) {
    ....
  }
  ....
}

Identical errors can be found in some other places:

  • V746 Type slicing. An exception should be caught by reference rather than by value. iocommand.cpp 2650
  • V746 Type slicing. An exception should be caught by reference rather than by value. projectpopup.cpp 522
  • V746 Type slicing. An exception should be caught by reference rather than by value. projectpopup.cpp 537
  • And 8 additional diagnostic messages.

Open X-Ray Engine

V746 Type slicing. An exception should be caught by reference rather than by value. object_item_script.cpp 39


ObjectFactory::ServerObjectBaseClass *
CObjectItemScript::server_object    (LPCSTR section) const
{
  ObjectFactory::ServerObjectBaseClass *object = nullptr;

  try {
    object = m_server_creator(section);
  }
  catch(std::exception e) {
    Msg("Exception [%s] raised while creating server object "
        "from section [%s]", e.what(),section);
    return        (0);
  }
  ....
}


Do you make errors in the code?

Check your code
with PVS-Studio

Static code analysis
for C, C++ and C#

goto PVS-Studio;