MCPcopy Create free account
hub / github.com/ImageEngine/cortex / formatInternal

Function formatInternal

src/IECorePython/ExceptionAlgo.cpp:48–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46{
47
48std::string formatInternal(
49 const handle<> &exceptionHandle, const handle<> &valueHandle, const handle<> &tracebackHandle,
50 bool withStacktrace, int *lineNumber = nullptr
51)
52{
53 object exception( exceptionHandle );
54
55 // `valueHandle` and `tracebackHandle` may be null.
56 object value;
57 if( valueHandle )
58 {
59 value = object( valueHandle );
60 }
61
62 object traceback;
63 if( tracebackHandle )
64 {
65 traceback = object( tracebackHandle );
66 }
67
68 if( lineNumber )
69 {
70 if( PyErr_GivenExceptionMatches( value.ptr(), PyExc_SyntaxError ) )
71 {
72 *lineNumber = extract<int>( value.attr( "lineno" ) );
73 }
74 else if( traceback )
75 {
76 *lineNumber = extract<int>( traceback.attr( "tb_lineno" ) );
77 }
78 }
79
80 object tracebackModule( import( "traceback" ) );
81
82 object formattedList;
83 if( withStacktrace )
84 {
85 formattedList = tracebackModule.attr( "format_exception" )( exception, value, traceback );
86 }
87 else
88 {
89 formattedList = tracebackModule.attr( "format_exception_only" )( exception, value );
90 }
91
92 object formatted = str( "" ).join( formattedList );
93 std::string s = extract<std::string>( formatted );
94
95 return s;
96}
97
98std::tuple<handle<>, handle<>, handle<>> currentPythonException()
99{

Callers 2

formatPythonExceptionFunction · 0.85
translatePythonExceptionFunction · 0.85

Calls 2

joinMethod · 0.80
strFunction · 0.70

Tested by

no test coverage detected