Your question (and code) have nothing to do with Qt. Using the Qt library does not change the handling of C++ exceptions. The following code based on yours does not crash and outputs "Failed" here (GCC 6.4, nothing to do with Qt).
#include <iostream>
#include <exception>
namespace Test {
class ExceptionEx: public std::exception
{
public:
explicit ExceptionEx(const char* message): msg_(message) { }
explicit ExceptionEx(const std::string& message): msg_(message) {}
virtual ~ExceptionEx() throw () {}
virtual const char* what() const throw () { return msg_.c_str(); }
protected:
std::string msg_;
};
}
namespace Test{
class ExceptionEx; // Class which is inherited std::exception
// It, class ExceptionEx, is defined on another cpp file
class Class1{
public:
Class1() throw(ExceptionEx);
};
Class1::Class1() throw(ExceptionEx){
throw ExceptionEx( "exception" );
}
void func( void ){
try{
Class1 obj;
}catch( ExceptionEx &e ){
std::cout << "Failed" << std::endl;
}
}
}
int main(void)
{
Test::func();
}
#include <iostream>
#include <exception>
namespace Test {
class ExceptionEx: public std::exception
{
public:
explicit ExceptionEx(const char* message): msg_(message) { }
explicit ExceptionEx(const std::string& message): msg_(message) {}
virtual ~ExceptionEx() throw () {}
virtual const char* what() const throw () { return msg_.c_str(); }
protected:
std::string msg_;
};
}
namespace Test{
class ExceptionEx; // Class which is inherited std::exception
// It, class ExceptionEx, is defined on another cpp file
class Class1{
public:
Class1() throw(ExceptionEx);
};
Class1::Class1() throw(ExceptionEx){
throw ExceptionEx( "exception" );
}
void func( void ){
try{
Class1 obj;
}catch( ExceptionEx &e ){
std::cout << "Failed" << std::endl;
}
}
}
int main(void)
{
Test::func();
}
To copy to clipboard, switch view to plain text mode
I suspect the crash is coming from elsewhere.
Bookmarks