-1

everyone, i tried finding a solution on the internet, yet i've failed and i need your help.

I need to write a programm which has the following property:

If it crashes - it should write the time of the crash and the line, where it occured.

I've made a special logging function for this purpose, however - i have no idea how to intercept the crash event and make it write to the logfile - just after the crash occured.

I would really appreciate your help.

Arthur Klezovich
  • 2,595
  • 1
  • 13
  • 17
  • Does [how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes](http://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes) help ? – Jakob Kroeker Jul 19 '13 at 15:12

2 Answers2

1

You can use std::uncaught_exception in your destructor to check if the stack is unwinding because of an exception and if it's the case write a scoped log entry.

There may also be some interesting information for you in this thread. It contains a lot of useful information about good and bad practice when it comes down to exception handling.

Community
  • 1
  • 1
user2573221
  • 494
  • 4
  • 13
0

Depends on how you want to implement it.

Let me explain exactly what your trying to catch on a crash.

These are called unhandled exceptions. These are read passed the C++ exception handlers and are considered OS level exception handling. This means your implementation of where and how you catch your errors is OS dependent. (very important)

I only know windows so.... here is the ways you can do it in the windows platform.

three ways.

  • __try __except -- basically like try catch but lower level

  • catching signals -- google this if you want there pretty useless in my opinion not going to even bother explaining

  • my recommend solution is

    SetUnhandledExceptionFilter

progrenhard
  • 2,333
  • 2
  • 14
  • 14