Can I run streams inside try {}?
And what to do when an exception is sent? Wait for other threads to complete?
Does std :: thread have a mechanism for stopping all threads, well, or specific tools for solving a similar problem? Or do you have to do everything manually?
try{ // ΡΡΠ°ΡΡΡΡΡ ΠΏΠΎΡΠΎΠΊΠΈ }catch(std::exception ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅) { std::cout << "..."; } ΠΏΠΎΡΠΎΠΊ1 { // ΠΏΡΠΈ Π²ΡΠ·ΠΎΠ²Π΅ Π²Π΅Π΄Π΅Ρ ΠΊ Π½Π΅ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½Π½ΠΎΠΌΡ ΠΏΠΎΠ²Π΅Π΄Π΅Π½ΠΈΡ. // ΠΌΠΎΠΆΠ΅Ρ Π²ΡΠΏΠΎΠ»Π½ΠΈΡΡΡ ΠΌΠΎΠΆΠ΅Ρ Π½Π΅Ρ throw std::exception(ΡΡΡΠΎΠΊΠ°); } ΠΏΠΎΡΠΎΠΊ2 { throw std::exception(ΡΡΡΠΎΠΊΠ°); }
And how can I report to the main stream? that an exception occurred in thread 1? Global variables?
try { // ΡΡΠ°ΡΡΡΡΡ ΠΏΠΎΡΠΎΠΊΠΈ ΠΏΠΎΡΠΎΠΊ1; ΠΏΠΎΡΠΎΠΊ2; // Π·Π΄Π΅ΡΡ Π²Π΅ΡΠ½ΡΠΉ ΡΠΈΠΊΠ» while(true) { ... ΠΎΡΠ½ΠΎΠ²Π½ΠΎΠΉ ΠΏΠΎΡΠΎΠΊ }; }catch(std::exception ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅) { std::cout << "..."; } ΠΏΠΎΡΠΎΠΊ1 { try{ .. throw std::exception(ΡΡΡΠΎΠΊΠ°); .. } catch(std::exception ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅) { } } ΠΏΠΎΡΠΎΠΊ2 { try{ .. throw std::exception(ΡΡΡΠΎΠΊΠ°); .. } catch(std::exception ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅) { } }