While browsing System.Zip (Delphi XE2) to see how it works, I found this function:
procedure VerifyWrite(Stream: TStream; var Buffer; Count: Integer);
begin
if Stream.Write(Buffer, Count) <> Count then
raise EZipException.CreateRes(@SZipErrorWrite) at ReturnAddress;
end;
It’s the at ReturnAddress part that sort of puzzles me.
I didn’t know that at was a valid keyword (the syntax highlighter doesn’t seem to recognise it either).
According to the IDE it’s declared as System.ReturnAddress, but I can only find it declared as a label somewhere in the (asm) code of procedure _HandleAnyException;. The system unit is full of references to it though.
So what I would like to know is this:
- What is
ReturnAddress? - What exactly does
Raise Exception.Create ... at ReturnAddressdo?
Bonuspoints if you can give a real-world example of where this would be a useful construct, or if you can advice against using it.
ReturnAddressis the address to whichVerifyWritewould have returned when finished.Raise Exception.Create... at ReturnAddressmeans that when the exception dialog is displayed, it would indicate the address of the exception as being atReturnAddress. In other words, the exception message would readException <whatever> raised at <ReturnAddress>: <Exception Message>.Here is an excerpt from the help file for Delphi 7. It’s nearly the same as the online version.
Note the last sentence in particular. It’s pretty specific about the use of
at <address>.