我有这个代码:
public void myFunction(String label, String type, string command, int attempts = 0)
{
try
{
Utility.Logger("myFunction attempt " + attempts.ToSafeString() + " label " + label + " type " + type, command);
...stuff...
}
catch (Exception e)
{
if (attempts < 10)
return myFunction(label, type, command, attempts++);
else
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我在catch分支中有一个递归调用,在这里我设置一个参数一个counter = counter + 1.
奇怪的是我在日志中总是尝试= 0.为什么?我错过了什么?
| 归档时间: |
|
| 查看次数: |
56 次 |
| 最近记录: |