EOleException error raised with message catastrophic failure or access is denied in Delphi
While calling DLLs from my application using safecall, I was getting EOleException error raised with message catastrophic failure. When I switched to stdcall, I started getting EOleException error raised with message access is denied for some calls. So, I thought to dive deep into the root cause of the error and tried to understand what exactly EOleException is in Delphi?
As per documentation:
EOleException is the exception class for OLE automation errors that occur in methods or properties of an object.
EOleException is the exception class for errors specific to the OLE IDispatch interface.
EOleException is raised when an error occurs in the middle of a method call from IDispatch. EOleException is generated when a server receives a failure return value from a property or method that was called with the IDispatch interface Invoke method.
When an error occurs, objects invoked through IDispatch can return essential information about the exception, including the source of the error, error code, description, help file, and ID number for context-sensitive help. EOleException captures this information, and the error description and ID number (if available) are included in a message generated by the constructor; the other information is stored in the Source and HelpFile properties defined for EOleException and the ErrorCode property inherited from EOleSysError.
Solution:
1. Try catching the error
try
....
....
except
on e: EOleException do
begin
....
....
end;
end;
2. Ignore the error
To stop Delphi from breaking, you will need to configure Delphi to ignore the exception by telling it that the application will handle the exception. Go to Tools > Debugger Options, on the "Language Exceptions" tab add "EOleException". Ensure that it is ticked, which tells the Delphi environment to ignore the exception (and let the code run).