Discussion:
Exception Handling and re-raising
(too old to reply)
Allen Vander Meulen
2003-09-25 19:45:11 UTC
Permalink
OK, I'm puzzled.

I can write code in C++ that allows me to clean up following specific
types of exceptions and then re-raise them to "bubble up" to the
calling procedure for further recovery. I've tried just about every
variation of this that I can think of in Delphi, and none work, or
produce odd behavior. Does anyone have any suggestions?

This works (obviously) ...

try
{ ... }
raise ECustomException;
{ ... }
except
on e: ECustomException do dothis; // (a single line of code)
else
dothat;
end;

And this works (also, obviously) ...

try
{ ... }
raise ECustomException;
{ ... }
except
dothis;
dothat;
raise;
end;

However, if I use the "on ... do" construct, I can't re-raise
exceptions, or do anything requiring multiple statements, like this:

try
{ ... }
raise ECustomException;
{ ... }
except
on e: ECustomException do
begin
dothis;
dothat;
raise;
end;
else
begin
dothat;
raise;
end;
end;

- Allen
Jose Perez
2003-09-26 14:53:46 UTC
Permalink
Post by Allen Vander Meulen
OK, I'm puzzled.
I can write code in C++ that allows me to clean up following specific
types of exceptions and then re-raise them to "bubble up" to the
calling procedure for further recovery. I've tried just about every
variation of this that I can think of in Delphi, and none work, or
produce odd behavior. Does anyone have any suggestions?
This should be posted in comp.lang.pascal.delphi.misc or
comp.lang.pascal.delphi If you check the FAQ, you also note that this news
(comp.lang.pascal), is no longer active.
Post by Allen Vander Meulen
This works (obviously) ...
try
{ ... }
raise ECustomException;
{ ... }
except
on e: ECustomException do dothis; // (a single line of code)
else
dothat;
end;
And this works (also, obviously) ...
try
{ ... }
raise ECustomException;
{ ... }
except
dothis;
dothat;
raise;
end;
However, if I use the "on ... do" construct, I can't re-raise
try
{ ... }
raise ECustomException;
{ ... }
except
on e: ECustomException do
begin
dothis;
dothat;
raise;
end;
else
begin
dothat;
raise;
end;
end;
- Allen
Loading...