HaxeFoundation / HaxeFoundation/haxe

[cpp] modulo zero can't be caught / causes a hard crash

Open
#7,034 34 comments 0 reactions 5 assignees Claimed by @RealyUniqueName View on GitHub
platform-flash platform-java platform-neko platform-php platform-python
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

The following code causes a hard crash on the cpp target that can't be caught, which is a problem for tools like [crashdumper](https://github.com/larsiusprime/crashdumper):

```haxe
class Main {
public static function main() {
var zero = 0;
try {
trace(1 % zero);
} catch (e:Dynamic) {
trace(e);
}
}
}
```

```
Error: Command failed with error -1073741676
```

![](https://i.imgur.com/4HsgFsx.png)

`-debug` and the usual defines (`-D HXCPP_CHECK_POINTER`, `-D HXCPP_STACK_TRACE`) don't seem to help.

Other targets either don't throw an exception at all, or one that can at least be caught:

- Java: `source/Main.hx:7: System.DivideByZeroException: Attempted to divide by zero.`
- C#: `source/Main.hx:7: java.lang.ArithmeticException: / by zero`
- Neko: `source/Main.hx:7: Invalid operation (%)`
- JavaScript: `source/Main.hx:5: NaN`

Haxe version: eecfbebb084f5faf6d08c68b020162c1f221816f
HXCPP version: https://github.com/HaxeFoundation/hxcpp/commit/8753da50bb642214c28a63294eca8a2afa39a420

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.