c++ - More information from std::exception -


i'm writting qt-application arm-processor. use gcc-linaro-arm-linux-gnueabihf compiller.

i try caught std::exception

try {            ----code here---- } catch(qexception e) {     qcritical() << e.what(); } catch(std::exception e) {     qcritical() << e.what(); } 

as output have:

----- dev started ----- std::exception ----- dev finished ----- 

there no detailed information exception.

ho can see kind of std::excpetpion occured?

the problem, it's qt application. makefile generated qmake. can't directly pass options gcc compiller.

the problem you're slicing exception object—you're catching value, subclass information lost. catch const & instead keep type & data alive:

catch(const std::exception &e) {     qcritical() << e.what(); } 

additionally, if want special handling more specific types (classes derived std::exception), can add it:

catch (const std::invalid_argument &e) {   qcritical() << "invalid argument: " << e.what(); } catch (const std::domain_error &e) {   qcritical() << "domain error: " << e.what(); } catch (const std::excetion &e) {   qcritical() << "other exception: " << e.what(); } 

note order of catch clauses important: processed sequentially, , first 1 matching used. derived classes have listed before base class.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -