madExcept, getting top of current stack
Asked Answered
F

1

5

In an delphi 2007 application, we have used madExcept to handle exeptions for us. We use the standard dialog, letting the user send us a report with mail if he want to.

We want to add a little to this functionality. If the user choose not to send a full report, we still want to log the exception to a file, but not a full report. We want the exception class and message, and the source file and line number.

The first two is easy, but I can't find a straight forward way of finding the latter.

I have the full exception report in the form of an IMEException interface. As far as I can see, the call stack is available only through the BugReportSections property, which gives me the stack in plain text.

In madStackTrace.pas, there is a StackTrace( )-function that should give me what I want. It takes a lot of parameters, and the documentation is a little short on information..

Question: Does anybody know the right parameters to feed into StackTrace( ), so that it only return the top item of the stack from the thread where the exception was thrown?

Fouquet answered 7/1, 2011 at 12:18 Comment(0)
S
5

madStackTrace.pas has another function, StackAddrToStr that just takes a single address and returns the formatted text for it. If you're in the except block for the crashing thread you can pass the global ExceptAddr variable to it. If you're in one of the madExcept callbacks use `IMEException.ExceptAddr' instead.

Syndrome answered 7/1, 2011 at 16:0 Comment(4)
Still returning a string, but this one lead me to GetMapFileInfos( ) from madMapFile.pas, which may give me what I want.Fouquet
I think I may have found what I need for StackTrace, though: StackTrace(true, false, false, @stack, exception.ExceptAddr, true, false);Fouquet
I'm sorry, but soon after this question, I switched workplace. I do remember solving the issue, but I no longer have access to the code to see the solution. I'm not sure if its right to mark the answer as accepted. It's not a direct answer to the question, even though it was helpful (which earn it a upvote...)Fouquet
madStackTrace.StackAddrToStr(ExceptAddr) gets the line number for me, thanks Craig!Iconoclast

© 2022 - 2024 — McMap. All rights reserved.