integrated-application-development / integrated-application-development/sonar-delphi

New rule: Heap exceptions should not be created

Open
#61 1 comment 0 reactions 0 assignees View on GitHub
feature good first issue rule
Dominant language
Java
Stars
159
Forks
31
Avg merge
5d 4h
Merged PRs (30d)
4

Description

### Prerequisites

- [X] This rule has not already been suggested.
- [X] This should be a new rule, not an improvement to an existing rule.
- [X] This rule would be generally useful, not specific to my code or setup.

### Suggested rule title

Heap exceptions should not be created

### Rule description

This rule would detect constructor calls of all types inheriting from `EHeapException` (`EOutOfMemory` and `EInvalidPointer`).

### Rationale

Exceptions descending from `EHeapException` have their memory pre-allocated at the start of the application. Creating them at runtime is at best misleading and at worst has unpredictable consequences.

See [the Embarcadero documentation](https://docwiki.embarcadero.com/Libraries/Sydney/en/System.SysUtils.EHeapException):

> Note: Memory for these exceptions is pre-allocated whenever an application starts and remains allocated as long as the application is running. Never raise EHeapException or its descendants directly.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.