Return to C ++ development after a 12-year hiatus. I use the JetBrains CLion software, which is great as it provides a big contribution to possible problems in my class. One of the warnings that I get in the instructions to create the class constructor: Thrown exception type is not nothrow copy constructible. Here is an example of the code that generates this warning:
Thrown exception type is not nothrow copy constructible
#include <exception> #include <iostream> using std::invalid_argument; using std::string; class MyClass { public: explicit MyClass(string value) throw (invalid_argument); private: string value; }; MyClass::MyClass(string value) throw (invalid_argument) { if (value.length() == 0) { throw invalid_argument("YOLO!"); // Warning is here. } this->value = value; }
This piece of code compiles and I can unit test it. But I would really like to get rid of this warning (in order to understand what I'm doing wrong, even if it compiles).
thank
, , . ++ 11 throw noexcept. :
throw
noexcept
explicit MyClass(string value) noexcept(false);
, noexcept(false) , noexcept noexcept(true), :
noexcept(false)
noexcept(true)
explicit MyClass(string value);
, "Throw exception type not notrow copy constructible", , .
Source: https://habr.com/ru/post/1687339/More articles:Loop optimization on a large data file in R, possibly using Rcpp - performanceutf16 vs utf-16 - pythonWhy does this dotnet test test only work in a Docker container? - dockerbook application crashes on the screen saver (solid loading wheel) - ion - iosBinary Search Comparison - javaIdentification of stream reduction versus idempotent value - javaarangodb AQL How to change the value of an object in a nested array? - arangodbComputing projection matrices in J - matrixhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1687343/trying-to-prevent-duplicate-values-to-be-added-to-an-array&usg=ALkJrhht1eYhmmQ9kyDRF8zgt3uD7YL76wjava 8 handling custom exceptions when using Collectors.toMap - javaAll Articles