Why is except not catching this error?

强颜欢笑 提交于 2019-12-30 09:28:28

问题


I have a program that simulates dice rolls and compares them to values in a chart (set of String lists). I currently get the value from a TEdit. If the box is empty it raises a EConvertError that should be caught by my Try/Except statement, but it's not. Thoughts and advice? Code below, 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;

回答1:


'Stop on Delphi exceptions' is checked in the debugger options. The exception is actually caught just fine, but the IDE stops when you get it. When you continue running, you will not see the exception, but your message instead. Out of the IDE it will run fine.

You can uncheck this option (I usually do). You can always re-check it when you need to debug some stubborn problem.



来源:https://stackoverflow.com/questions/7930102/why-is-except-not-catching-this-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!