Print only part of a stack trace

Dennis dkorpel at gmail.com
Wed Jul 1 18:30:15 UTC 2020


On Wednesday, 1 July 2020 at 18:05:09 UTC, Jacob Carlborg wrote:
> [1] 
> https://dlang.org/phobos/core_runtime.html#.Runtime.traceHandler

Thanks, but I don't want to re-implement the default trace 
handler, I want to use it on a specific location and capture its 
output. I'll be more specific in what I want to achieve.

I have a function that checks a global error constant of a C 
library (OpenGL) like this:
```
void assertNoOpenGLErrors() {
     if (glGetError() != GL_NO_ERROR) {
         assert(0); // stack trace points to here instead of caller
     }
}
```

And I would like to rewrite it to this:
```
void assertNoOpenGLErrors() {
     if (glGetError() != GL_NO_ERROR) {
         print(getStackTrace().filterTrace());
         exit();
     }
}
```

So that the stack trace immediately points to the function that 
raised the OpenGL error, instead of it being buried in a large 
trace.


More information about the Digitalmars-d-learn mailing list