Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is except not catching this error?

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;
like image 283
Aaron Avatar asked Oct 28 '11 13:10

Aaron


1 Answers

'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.

like image 123
GolezTrol Avatar answered Nov 05 '22 05:11

GolezTrol