代码检查:try 语句不受支持
此检查会报告由 Burst 编译器 编译的代码中包含的 try 语句。
Burst 不支持诸如 try、 catch 和 finally 等异常处理构造。
示例
在此示例中,Burst 编译作业的 执行 方法中包含一个 try-finally 代码块。 不支持此操作,会被标记出来。
using Unity.Burst;
using Unity.Jobs;
[BurstCompile]
public struct ExampleJob : IJob
{
public void Execute()
{
// Reported: try-finally is not supported in Burst
try
{
}
finally
{
}
}
}
using Unity.Burst;
using Unity.Jobs;
[BurstCompile]
public struct ExampleJob : IJob
{
public void Execute()
{
// Correct: Remove exception handling and use explicit checks
var isValid = true;
if (!isValid)
return;
}
}
快速修复
此检查不提供专用快速修复。 手动修复方法是从 Burst 编译的代码中移除 try 语句。
2026年 5月 8日