Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow throwing of edm::Exceptions from python
Only a selected set of edm::errors codes are allowed.
- Loading branch information
Showing
4 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,26 @@ | ||
#include "FWCore/PythonParameterSet/interface/PyBind11Wrapper.h" | ||
#include "FWCore/Utilities/interface/Exception.h" | ||
//#include <iostream> | ||
#include "FWCore/Utilities/interface/EDMException.h" | ||
namespace edm { | ||
|
||
void pythonToCppException(const std::string& iType, const std::string& error) { | ||
auto colon = error.find(':'); | ||
if (colon != std::string::npos) { | ||
if (error.substr(0, colon) == "EDMException") { | ||
auto errorNameStart = error.find('{'); | ||
auto errorNameEnd = error.find('}'); | ||
if (errorNameStart != std::string::npos and errorNameEnd != std::string::npos) { | ||
auto errorName = error.substr(errorNameStart + 1, errorNameEnd - errorNameStart - 1); | ||
if ("Configuration" == errorName) { | ||
auto newLine = error.find('\n', errorNameEnd + 1); | ||
if (newLine == std::string::npos) { | ||
newLine = errorNameEnd + 1; | ||
} | ||
throw edm::Exception(edm::errors::Configuration) << error.substr(newLine + 1, std::string::npos); | ||
} | ||
} | ||
} | ||
} | ||
throw cms::Exception(iType) << " unknown python problem occurred.\n" << error << std::endl; | ||
} | ||
} // namespace edm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters