Skip to content

Commit bd9f9af

Browse files
ZwFinkevan-charmworks
authored andcommitted
Include information about uncaught exceptions in user code (#3442)
1 parent 34c2e11 commit bd9f9af

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/ck-core/init.C

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,10 +1274,27 @@ void _sendReadonlies() {
12741274
*/
12751275
void _initCharm(int unused_argc, char **argv)
12761276
{
1277-
int inCommThread = (CmiMyRank() == CmiMyNodeSize());
1277+
int inCommThread = (CmiMyRank() == CmiMyNodeSize());
12781278

1279-
DEBUGF(("[%d,%.6lf ] _initCharm started\n",CmiMyPe(),CmiWallTimer()));
1280-
std::set_terminate([](){ CkAbort("Unhandled C++ exception in user code.\n");});
1279+
DEBUGF(("[%d,%.6lf ] _initCharm started\n",CmiMyPe(),CmiWallTimer()));
1280+
std::set_terminate([](){
1281+
std::exception_ptr exptr = std::current_exception();
1282+
if (exptr)
1283+
{
1284+
try
1285+
{
1286+
std::rethrow_exception(exptr);
1287+
}
1288+
catch (std::exception &ex)
1289+
{
1290+
CkAbort("Unhandled C++ exception in user code: %s.\n", ex.what());
1291+
}
1292+
}
1293+
else
1294+
{
1295+
CkAbort("Unhandled C++ exception in user code.\n");
1296+
}
1297+
});
12811298

12821299
CkpvInitialize(size_t *, _offsets);
12831300
CkpvAccess(_offsets) = new size_t[32];

0 commit comments

Comments
 (0)