perf : 异常处理替换为YOO的异常类

This commit is contained in:
何冠峰
2025-12-05 15:45:04 +08:00
parent 5da8c6baf8
commit e5d0a856a5
27 changed files with 243 additions and 74 deletions
@@ -22,7 +22,7 @@ namespace YooAsset
add
{
if (IsValidWithWarning == false)
throw new System.Exception($"{nameof(AllAssetsHandle)} is invalid");
throw new YooHandleException($"{nameof(AllAssetsHandle)} is invalid. It may have been released or the provider was destroyed.");
if (Provider.IsDone)
value.Invoke(this);
else
@@ -31,7 +31,7 @@ namespace YooAsset
remove
{
if (IsValidWithWarning == false)
throw new System.Exception($"{nameof(AllAssetsHandle)} is invalid");
throw new YooHandleException($"{nameof(AllAssetsHandle)} is invalid. It may have been released or the provider was destroyed.");
_callback -= value;
}
}
@@ -22,7 +22,7 @@ namespace YooAsset
add
{
if (IsValidWithWarning == false)
throw new System.Exception($"{nameof(AssetHandle)} is invalid");
throw new YooHandleException($"{nameof(AssetHandle)} is invalid. It may have been released or the provider was destroyed.");
if (Provider.IsDone)
value.Invoke(this);
else
@@ -31,7 +31,7 @@ namespace YooAsset
remove
{
if (IsValidWithWarning == false)
throw new System.Exception($"{nameof(AssetHandle)} is invalid");
throw new YooHandleException($"{nameof(AssetHandle)} is invalid. It may have been released or the provider was destroyed.");
_callback -= value;
}
}
@@ -21,7 +21,7 @@ namespace YooAsset
add
{
if (IsValidWithWarning == false)
throw new System.Exception($"{nameof(RawFileHandle)} is invalid");
throw new YooHandleException($"{nameof(RawFileHandle)} is invalid. It may have been released or the provider was destroyed.");
if (Provider.IsDone)
value.Invoke(this);
else
@@ -30,7 +30,7 @@ namespace YooAsset
remove
{
if (IsValidWithWarning == false)
throw new System.Exception($"{nameof(RawFileHandle)} is invalid");
throw new YooHandleException($"{nameof(RawFileHandle)} is invalid. It may have been released or the provider was destroyed.");
_callback -= value;
}
}
@@ -23,7 +23,7 @@ namespace YooAsset
add
{
if (IsValidWithWarning == false)
throw new System.Exception($"{nameof(SceneHandle)} is invalid !");
throw new YooHandleException($"{nameof(SceneHandle)} is invalid. It may have been released or the provider was destroyed.");
if (Provider.IsDone)
value.Invoke(this);
else
@@ -32,7 +32,7 @@ namespace YooAsset
remove
{
if (IsValidWithWarning == false)
throw new System.Exception($"{nameof(SceneHandle)} is invalid !");
throw new YooHandleException($"{nameof(SceneHandle)} is invalid. It may have been released or the provider was destroyed.");
_callback -= value;
}
}
@@ -22,7 +22,7 @@ namespace YooAsset
add
{
if (IsValidWithWarning == false)
throw new System.Exception($"{nameof(SubAssetsHandle)} is invalid");
throw new YooHandleException($"{nameof(SubAssetsHandle)} is invalid. It may have been released or the provider was destroyed.");
if (Provider.IsDone)
value.Invoke(this);
else
@@ -31,7 +31,7 @@ namespace YooAsset
remove
{
if (IsValidWithWarning == false)
throw new System.Exception($"{nameof(SubAssetsHandle)} is invalid");
throw new YooHandleException($"{nameof(SubAssetsHandle)} is invalid. It may have been released or the provider was destroyed.");
_callback -= value;
}
}
@@ -166,10 +166,10 @@ namespace YooAsset
// 注意:正在加载中的任务不可以销毁
if (_steps == ESteps.LoadBundleFile)
throw new Exception($"Bundle file loader is not done : {LoadBundleInfo.Bundle.BundleName}");
throw new YooInternalException($"Cannot destroy loader while loading bundle : {LoadBundleInfo.Bundle.BundleName}");
if (RefCount > 0)
throw new Exception($"Bundle file loader ref is not zero : {LoadBundleInfo.Bundle.BundleName}");
throw new YooInternalException($"Cannot destroy loader with non-zero ref count {RefCount} : {LoadBundleInfo.Bundle.BundleName}");
if (Result != null)
Result.UnloadBundleFile();
@@ -265,18 +265,18 @@ namespace YooAsset
public void ReleaseHandle(HandleBase handle)
{
if (RefCount <= 0)
throw new System.Exception("Should never get here !");
throw new YooInternalException($"Attempting to release handle when RefCount is already zero. Asset : {MainAssetInfo.AssetPath}");
if (_resManager.UseWeakReferenceHandle)
{
// TODO 高危风险:如果移除弱引用失败,会导致资源永远无法释放。
if (RemoveWeakReference(handle) == false)
throw new System.Exception("Should never get here !");
throw new YooInternalException($"Handle not found in weak reference list. Asset: {MainAssetInfo.AssetPath}");
}
else
{
if (_handles.Remove(handle) == false)
throw new System.Exception("Should never get here !");
throw new YooInternalException($"Handle not found in cache list. Asset: {MainAssetInfo.AssetPath}");
}
// 引用计数减少
@@ -385,7 +385,7 @@ namespace YooAsset
}
if (status.TotalBytes == 0)
throw new System.Exception("Should never get here !");
throw new YooInternalException("Download total size can not be zero.");
status.IsDone = status.DownloadedBytes == status.TotalBytes;
status.Progress = (float)status.DownloadedBytes / status.TotalBytes;