URL: https://linuxfr.org/forums/programmation-c/posts/d%C3%A9clencher-et-capturer-une-exception Title: Déclencher et capturer une exception Authors: Pinaraf Date: 2004年10月25日T18:19:23+02:00 Tags: Score: 0 Bonjour En ce moment, je programme une librairie. Elle ne peux donc utiliser std::cerr pour afficher les erreurs, et j'aimerais faire comme j'ai l'habitude en python : déclencher des exceptions. J'ai essayé ceci, mais ça ne marche pas : _La fonction :_ bool rename_file(std::string source, std::string destination) { std::ifstream flux_in; std::ofstream flux_out; std::string ligne; //fpkg_exception the_exception; if (!is_file(source)) { throw "File not found"; return false; } return true; } C'est volontairement réduit, bien sûr... Maintenant, j'essaye de l'utiliser : try { rename_file("/test", "/bin")); } catch (...) { std::cerr << "Caught exception " << std::endl; return -1; } Ça marche, mais je ne suis pas satisfait. J'aimerais obtenir le texte de l'exception. J'ai essayé sans succès : 1- catch (std::string e) 2- catch (std::string *e) 3- catch (std::exception e) 3- catch (std::exception *e) Je pense que ça vient de ma façon de renvoyer l'erreur. Comment corriger ça ? Merci d'avance

AltStyle によって変換されたページ (->オリジナル) /