我有一个程序可以模拟掷骰子并将其与图表(一组字符串列表)中的值进行比较。我目前从 TEdit 获取值。如果该框为空,则会引发 EConvertError,该错误应该由我的 Try/Except 语句捕获,但事实并非如此。想法和建议?下面的代码,Delphi 7。
try
//Shooting
if ShootingRadio.Checked then
BS := StrToInt(Edit1.Text);
Randomize;
Roll := RandomRange(1,7);
Label3.Caption := IntToStr(Roll);
if (Roll < StrToInt(ShootingHitChart[BS-1])) then
begin
Label3.Caption := (IntToStr(Roll)+' Miss');
RichView1.AddTextNL((IntToStr(Roll)+' Miss'),7,0,1);
RichView1.Reformat;
end
else
begin
Label3.Caption := (IntToStr(Roll)+' Hit');
RichView1.AddTextNL((IntToStr(Roll)+' Hit'),6,0,1);
RichView1.Reformat;
end;
except
MessageBox(0,'No number entered.','Error',mb_OK);
end;
最佳答案
在调试器选项中选中“出现 Delphi 异常时停止”。实际上,异常可以很好地捕获,但是当您捕获它时 IDE 就会停止。当您继续运行时,您将不会看到异常,而是看到消息。离开 IDE 后它会正常运行。
您可以取消选中此选项(我通常这样做)。当您需要调试一些顽固问题时,您可以随时重新检查它。
关于delphi - 为什么除了没有捕获这个错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7930102/