> Thanks, that all makes sense, I didn't realise it did re-raise the
exception
> if it was caught. However I tried both options and it didn't catch
either.
> Here's the actual code.
> try
> device_id := strtoint(get_markitem(2,msg));
> except
> on EConvertError do
> device_id := 0;
> end;
>
> I also tried
>
> try
> device_id := strtoint(get_markitem(2,msg));
> except
> device_id := 0;
> end;
>
> IT raises the exception when get_markitem(2,msg) returns a null string (
> result = ''). (is this a null string??)
Maybe I am not understanding how you want this to behave.
In the case where get_markitem returns '' both examples above
should catch the exception, set device_id to 0 and allow execution
to proceed.
In the example below if I click the button I get first
the "Oops" message and then the "Got here" message, showing
that the device_id did get zeroed.
Meaning that the exception WAS both raised and handled.
-ns
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
device_id:integer;
{ Private declarations }
function get_markitem(k:integer; msg:string):string;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function TForm1.get_markitem(k:integer; msg:string):string;
begin
result:='';
end;
procedure TForm1.Button1Click(Sender: TObject);
var msg:string;
begin
device_id:=1729;
try
device_id := strtoint(get_markitem(2,msg));
ShowMessage('Got here');
except on EConvertError do
begin
ShowMessage('Oops! EConvertError');
device_id:=0;
end;
end;
ShowMessage(Format('Got out device_id=%d',[device_id]));
end;
end.
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"