Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:29:18

0001 #ifndef FWCore_Utilities_ConvertException_h
0002 #define FWCore_Utilities_ConvertException_h
0003 
0004 #include <string>
0005 #include <exception>
0006 #include <functional>
0007 #include "FWCore/Utilities/interface/Exception.h"
0008 #include "FWCore/Utilities/interface/thread_safety_macros.h"
0009 
0010 namespace edm {
0011   namespace convertException {
0012     void badAllocToEDM();
0013     void stdToEDM(std::exception const& e);
0014     void stringToEDM(std::string& s);
0015     void charPtrToEDM(char const* c);
0016     void unknownToEDM();
0017 
0018     template <typename F>
0019     auto wrap(F iFunc) -> decltype(iFunc()) {
0020       // Caught exception is rethrown
0021       CMS_SA_ALLOW try { return iFunc(); } catch (cms::Exception&) {
0022         throw;
0023       } catch (std::bad_alloc&) {
0024         convertException::badAllocToEDM();
0025       } catch (std::exception& e) {
0026         convertException::stdToEDM(e);
0027       } catch (std::string& s) {
0028         convertException::stringToEDM(s);
0029       } catch (char const* c) {
0030         convertException::charPtrToEDM(c);
0031       } catch (...) {
0032         convertException::unknownToEDM();
0033       }
0034       //Never gets here
0035       typedef decltype(iFunc()) ReturnType;
0036       return ReturnType();
0037     }
0038   }  // namespace convertException
0039 }  // namespace edm
0040 
0041 #endif