Override assert handler

Walter Bright newshound2 at digitalmars.com
Mon Aug 19 21:03:15 UTC 2024


I actually do understand how shared libraries work.

What happens by default when an assert failure happens is the function:

```
core.exception._d_assertp(immutable(char*) file, uint line);
```
is called. That forwards the call to:

```
core.exception.onAssertError(string file, size_t line);
```
which then forwards the call to:
```
(*_assertHandler)(file,line,null);
```
and core.exception._assertHandler is the pointer to the function.

The default behavior of _assertHandler is:
```
throw staticError!AssertError(file, line);
```

Therefore, if you write your own _d_assertp function in the executable, it will 
override the library version in your executable. For code in the shared library, 
the shared library _d_assertp will be called.


------

To understand assert error handling, it's necessary to understand:

```
AssertHandler
assertHandler
assertHandler  (yes, two of them!)
_assertHandler
onAssertError
onAssertErrorMsg
AssertError
_d_assertp
_d_assert_msg
_d_assert
```

which is overly complex.


More information about the Digitalmars-d mailing list