How I could ignore the error msgbox if the uninstall.vsf file does not exists when calling LoadVCLStyle_UnInstall
function in this code?
I supposed that using a Try block with an empty Except will be enough as in other languages, but this is not the case.
// Import the LoadVCLStyle function from VclStylesInno.DLL
procedure LoadVCLStyle_UnInstall(VClStyleFile: String); external 'LoadVCLStyleA@{app}\uninstall.dll stdcall uninstallonly';
//E: Occurs when the uninstaller initializes.
function InitializeUninstall: Boolean;
begin
Result := True;
// Initialize the VCL skin style.
try
LoadVCLStyle_UnInstall(ExpandConstant('{app}\uninstall.vsf'));
except
finally
end;
end;
The possibility to check for the file existence beforehand was already mentioned.
The user TLama mentioned that the code in the question is not regular pascal program code, but Inno Setup script code and and that my answer doesn't apply in this case. Because the following text could be of interest for pascal programmers we keep it.
The EXCEPT
statement by itself doesn't handle the exception, it marks only the point where program execution should continue after an error has occured. When the exception isn't handled/caught in the EXCEPT ... END
block it will be transferd to the next higher EXCEPT
statement. (Freepacal reference guide chapter 17)
I also don't think that TRY ... EXCEPT ... FINALLY ... END
will work. Either EXCEPT
or FINALLY
, not both.
If you want to capture the exception you must do something like:
TRY
LoadVCLStyle_UnInstall(ExpandConstant('{app}\uninstall.vsf'));
EXCEPT
On EWhateverException DO ...;
END;
If the exception class for this error isn't defined in the documentation, you can use the following trick to find the exception class name:
TRY
LoadVCLStyle_UnInstall(ExpandConstant('{app}\uninstall.vsf'));
EXCEPT
ON Exception DO WriteLn(ExceptObject.ClassName);
END;
With ON Exception DO ..
you can catch any exception, but i don't recomend to use that variant for the definite program.