Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caller can not get exception after raising UpdateExceptMessage() #30

Open
avpnvpn opened this issue Jul 1, 2022 · 0 comments
Open

Caller can not get exception after raising UpdateExceptMessage() #30

avpnvpn opened this issue Jul 1, 2022 · 0 comments

Comments

@avpnvpn
Copy link

avpnvpn commented Jul 1, 2022

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.

@avpnvpn avpnvpn changed the title caller can not get exception after raise UpdateExceptMessage() Caller can not get exception after raising UpdateExceptMessage() Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant