std::runtime_error augabe macht probleme



  • Hallo,

    ich habe sowas:

    //irgendwo in einer funktion
    try{
           function();
    }
    catch (std::runtime_error& ex) 
    		{					
    
    			std::cerr << ex.what() << std::endl;
    		}
    
    //in function()
    void Class::function()
    {
          int a = 9;
          if(//irgendeine bedingung)
                throw std::runtime_error(std::cout << "hallo hier ist: " << a << std::endl;);
    }
    

    so gehts bei mir nicht.
    Bbis jetzt versuche ich es so aber so will es auch nicht:

    throw std::runtime_error("hallo hier ist: " + std::string(a));
    

    So schaffe ich es aber auch nicht - kann mir jemand helfen?



  • std::stringstream s;
    s << i;
    throw std::runtime_error("Blubb bla " + s.str());
    

    boost::lexical_cast wäre eine alternative.



  • Edit: Hab selten solchen Blödsinn geschrieben, besser löschen 😃

    Grüße,

    Martin


Anmelden zum Antworten