2015-04-10 3 views

risposta

2

Cosa stai cercando probabilmente sarebbe qualcosa di simile:

try { 
    // ... 
} 
template <typename Exc> 
catch (Exc const& ex) { 
    throw Exc(std::string("Custom message:") + ex.what()); 
} 

Almeno è così che avremmo fatto una cosa del genere in C++ in genere. Sfortunatamente, non puoi scrivere il codice del modello in un blocco di cattura del genere. Il meglio che puoi fare è aggiungere alcune informazioni sul tipo di runtime come stringa:

try { 
    // ... 
} 
catch (std::exception const& ex) { 
    throw std::runtime_error(std::string("Custom message from ") + 
          typeid(ex).name() + ": " + ex.what()); 
}