org.sonar.l10n.delphi.rules.community-delphi.MissingRaise.html Maven / Gradle / Ivy
The newest version!
Why is this an issue?
When writing an exception raise in Delphi, a common mistake is to omit the raise
,
causing the exception to be created but not actually used. This is bad for a number of reasons:
- The exception object is never freed, causing a memory leak.
- Control flow continues as usual, even though an undesired exceptional state has been reached.
- The bug is easy to miss but can greatly alter the path of execution.
How to fix it
Add the raise
keyword. If the exception is not required, delete the constructor invocation instead.
procedure DeleteDatabase;
begin
if InProductionEnvironment then begin
EDontBreakProduction.Create('DeleteDatabase attempted in production');
end;
Database.DeleteAllImportantRecords;
end;
procedure DeleteDatabase;
begin
if InProductionEnvironment then begin
raise EDontBreakProduction.Create('DeleteDatabase attempted in production');
end;
Database.DeleteAllImportantRecords;
end;
© 2015 - 2024 Weber Informatics LLC | Privacy Policy