function handleException(obj, Mex)
    if strncmp('Sldv:RunTestCase:',Mex.identifier,length('Sldv:RunTestCase:'))==0
        % Reset session data only for unknown errors. Otherwise session
        % is already cleared.
        finalExc = [];
        if strcmp(obj.SignalLoggingSaveFormat,'Dataset') && ...
                sldvshareprivate('util_is_related_exc', ...
                Mex, {'Simulink:logLoadBlocks:ToWksSigLogNoStrictBusMsg',...
                'Simulink:blocks:CannotFindSignalInStrictMode',...
                'Simulink:Bus:SigHierPropBusSelOutputDoesNotMatchInput'})
            finalExc = MException('Sldv:RunTestCase:UnableToSimulationOutput', getString(message('Sldv:RunTestCase:UnableToSimulationOutput', obj.UtilityName, obj.UtilityName)));
            finalExc = finalExc.addCause(Mex);
        end
        obj.resetSessionData;
        if ~isempty(finalExc)
            throw(finalExc);
        end
    end
    rethrow(Mex);
end

