% MException for an spf exception payload which the client can catch and
% handle

% Copyright 2020 The MathWorks, Inc.

classdef CheckedException < MException
    
    properties (SetAccess = immutable)
        % parallel.internal.cluster.types.ErrorCode enum identifying type of
        % checked exception
        ErrorCode
        
        % Struct holding any further information to handle exception.
        % Fields dependent on value of ErrorCode.
        Details
    end
    
    methods
        function obj = CheckedException(exceptionPayload)
            [msgID, msgText] = iExtractBaseException(exceptionPayload);
            obj@MException(msgID, msgText);
            obj.ErrorCode = exceptionPayload.code;
            obj.Details = exceptionPayload.details;
        end
    end
end

function [msgID, msgText] = iExtractBaseException(exceptionPayload)
    err = exceptionPayload.exception;
    msgID = err.identifier;
    msgText = err.message;
end