代码检查:不支持 Try 语句
此检查会报告 try 语句出现在由 Burst 编译器 编译的代码中。
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日