docs.unity.cn
    Show / Hide Table of Contents

    Method LogException

    LogException(AsyncOperationHandle, Exception)

    Write an exception as a log message.

    Declaration
    public static void LogException(AsyncOperationHandle op, Exception ex)
    Parameters
    Type Name Description
    AsyncOperationHandle op

    The operation handle.

    Exception ex

    The exception.

    Remarks

    LogException can be used to convert an exception to a log message. The exception is stringified. If the operation is in a failed state, the exception is logged at an Error logging level. If not the exception is logged at a Debug logging level. Addressables logs warnings and errors so if the operation is not in a failed state by default this function will not log.

    Examples
            public async Task<Material> LogExceptionSuccessfulTask(bool isErrored)
        {
            var loadHandle = Addressables.LoadAssetAsync<Material>("green.material");
            var material = await loadHandle.Task;
            if (loadHandle.Status == AsyncOperationStatus.Failed)
            {
                // something went wrong, log it and return the placeholder material
                Addressables.LogException(loadHandle, loadHandle.OperationException);
                return k_PlaceholderMaterial;
            }
            return material;
        }
    See Also
    Enable all logging

    LogException(Exception)

    Write an exception as a debug log message.

    Declaration
    public static void LogException(Exception ex)
    Parameters
    Type Name Description
    Exception ex

    The exception.

    Remarks

    LogException can be used to convert an exception to a log message. The exception is stringified and logged at a Debug logging level. Addressables logs warnings and errors so by default this function will not log.

    Examples
            public void LogExceptionDebugLogging(bool isErrored)
    {            
            try
            {
                if (isErrored)
                {
                    throw new Exception("Unable to complete task");
                }
    
            } catch(Exception e)
            {
                Addressables.LogException(e);
            }            
        }
    Back to top Copyright © 2023 Unity Technologies — Terms of use
    Generated by DocFX
    on Monday, June 26, 2023