1

I want to get the stack trace but it is always empty?

try{ int a = 5, b = 0; int c = a/b; } catch(Exception &e){ ShowMessage("Exception: " + e.Message + "\nStackTrace:" + e.StackTrace); } 

Using C++ Builder XE2.

Edit: This code executes on TForm1::Button1Click.

5
  • Are you in your main-function? Commented Feb 20, 2013 at 14:40
  • Are you sure a divide by zero results in Exception being thrown? Commented Feb 20, 2013 at 14:42
  • Yes, exception is thrown. I updated the post. Commented Feb 20, 2013 at 14:43
  • Isn't is ShowMessage("Exception: " + e.Message() + "\nStackTrace:" + e.StackTrace());? Commented Feb 20, 2013 at 14:45
  • No. StackTrace is UnicodeString (data member). Commented Feb 20, 2013 at 14:46

1 Answer 1

1

Found the answer here: https://forums.embarcadero.com/thread.jspa?messageID=419807&tstart=0

However, the property returns an empty string by default. It is designed so third-party exception loggers (MadExcept, EurekaLog, etc) can hook into it to provide the actual stack trace information. Why Embarcadero has chosen not to provide their own native implementation is anyone's guess.

Sign up to request clarification or add additional context in comments.

4 Comments

Like the answer says, you have to use a third-party solution, like one of the products listed, or write your own from scratch. Embarcadero does not provide a native stack tracer of their own.
Remove the additional question from your answer and mark it as accepted. Other SO users won't notice your question unless it is asked separately. If you want to know how to implement a stack trace using the hooks Embarcadero provided the best way is to implement it youself then create a new question if/when you get stuck.
The link above into the Embarcadero forum is broken. Can anyone provide a corrected link, or a cached copy of the forum entry?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.