Best Practice Exception Handing Addressables Key Not Found?

How would I add code to manage when a key is not found rather than throwing an error? (e.g. i cant figure out how and how to put in a try / catch with addressables?)

Example method below

**
Exception encountered in operation CompletedOperation, status=Failed, result= : Exception of type ‘UnityEngine.AddressableAssets.InvalidKeyException’ was thrown., Key=Occupations,


If there is no key found an error occurs when loading an addressable asset


public IList<GameObject> SpawnAssets(string key, int num, Transform spawnPos, IList<GameObject> list)
{
    Addressables.LoadAssetAsync<GameObject>(key).Completed += async asset =>
    {
        if (asset.Status == AsyncOperationStatus.Failed)
        {
            Debug.Log($"Key failed to load: {key}");
            return;
        }

        if (asset.Status == AsyncOperationStatus.Succeeded)
        {
            for (int i = 0; i < num; i++)
            {
                GameObject go = asset.Result;
                go = Instantiate(go, go.transform.position, go.transform.rotation);
                go.transform.SetParent(spawnPos, false);
                list.Add(go);
                go.name = $"Button{i}";
            }
        }

    };

    return list;
}

If I remember correctly, the addressables system actually catches and prints the exception for you so in theory it shouldn’t cause any undefined behaviour from the exception, however annoying it may be. Really the only way I can think to avoid having the errors printed would be to manually filter out invalid keys before trying to load the asset - last I checked there isn’t a way to get access to the original keys at runtime, just their hashed versions. A project I’ve worked on required the addressables to be cached on startup so I actually wrote an editor tool to help keep track of and serialize keys based on our naming convention (very much a hack, but it was necessary in our case).

Hey, not sure if this was a part of Addressables API when original question was asked, but here is an easy way to customize default Exception handling which is set to swallow exceptions and only log them in Editor.

I chose to throw them so I can handle them appropriately:

UnityEngine.ResourceManagement.ResourceManager.ExceptionHandler = (op, ex) => throw ex;

Thanks for the response and that helps clarify. Yes it annoying given my project uses a huge database therefore I can’t realistically avoid these exceptions albeit not causing other issues. I’ll look into catching the keys before they load your work around sounds interesting. Cheers