Caller can not get exception after raising UpdateExceptMessage()
In my case(D11.1), Imaging.UpdateExceptMessage() updates current exception E (normally get from GetException()) then E will be re-raised. But this causes the caller unable to catch the exception again since RTL will free the old exception after the raise.
try Format.SaveToFile(FileName, DataArray, False); // eg: Access denied except on e: Exception do ... ShowErrMsg(e.Message); // e is actually invalid and causes errors later //Project xxx.exe raised exception class EInvalidPointer with message 'Invalid pointer operation'. //Access violation at address 0040BB30 in module 'xxx'. Read of address 00000000. end;
I temporarily altered the code like this to make it work:
function UpdateExceptMessage(E: Exception; const MsgToPrepend: string; const Args: array of const): Exception; begin //Result := E; //E.Message := Format(MsgToPrepend, Args) + ' ' + SExceptMsg + ': ' + E.Message; Result := EImagingError.Create(Format(MsgToPrepend, Args) + ' ' + SExceptMsg + ': ' + E.Message); end;
Thanks.