main.cpp: In constructor ‘MyException::MyException()’:
main.cpp:6:7: error: no matching function for call to ‘std::invalid_argument::invalid_argument()’
main.cpp:6:7: note: candidates are:
In file included from main.cpp:2:0:
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/stdexcept:86:14: note: std::invalid_argument::invalid_argument(const string&)
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/stdexcept:86:14: note: candidate expects 1 argument, 0 provided
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/stdexcept:83:9: note: std::invalid_argument::invalid_argument(const std::invalid_argument&)
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/stdexcept:83:9: note: candidate expects 1 argument, 0 provided
main.cpp: In function ‘int main()’:
main.cpp:10:27: note: synthesized method ‘MyException::MyException()’ first required here
main.cpp:15:5: warning: exception of type ‘MyException’ will be caught [enabled by default]
main.cpp:12:5: warning: by earlier handler for ‘std::invalid_argument’ [enabled by default]
I think you need to throw an error object that is an instantiation of your exception class instead of the class name by itself.
Try doing throw MyException("what argument string");
I tried that and to my surprise it did not work.
I think you may have to type a constructor and have it call the super constructor.
By default the default constructor (the constructor that takes no arguments) will call the default constructor of the base classes. std::invalid_argument has no default constructor so MyException will not get a default constructor. If you want MyException to have a default constructor you will have to define it yourself, and specify what std::invalid_argument constructor you want to use in the constructor initialization list.
I tried that and to my surprise it did not work.
I think you may have to type a constructor and have it call the super constructor.
of course it doesnt work. in c++ classes dont have default constructors that take args. so doing that without writing a constructor that takes a string will flag an error.