Delphi Exception Logger

A free exception logging for Delphi with additional information like source files, procedure names, line numbers, exception messages, etc.

(c) Jiri Hajek 2003-2005
E-mail:   jh   at   j i r i h a j e k   dot   net
Created for MediaMonkey, a free mp3 jukebox player and music library organizer

When you include this unit in your project, all exceptions that happens at run-time are automatically logged together with exception message, information about source of the exception and call stack content together with source files and line numbers information.

This unit was tested under Delphi 7, it would probably work under other Delphi versions as well, but it might need some modifications in some magic constants in the code below.

  1. Include this unit in your project.
  2. You'll also need an excellent leak detector for Delphi, MemCheck. It's also a single Delphi unit and so it isn't any proble to install it. (Exception Logger uses its methods to analyze call stack).
  3. Modify OutputFile constant below so that logs are written to a file you want.
  4. Recommended: Set your compiler options for debugging. It's a good idea to turn on "Project|Options|Linker|Include TD32 debug info" because then you get complete reports about source files, procedure names and line numbers. On the other hand, it makes your compiled exe file much bigger.
  5. Compile and run! You can distribute such compiled file even to your users and they can directly report any problem to you. Any exception that happens is written to the OutputFile as in the file below. It is also reported using OutputDebugString() method and so it can be trapped for example by Debug View application from System Internals.

You can use this unit for any purpose, even commercial, as long as you leave this header here. Author cannot be blamed for any problem with this unit. If you don't agree, don't use it.

Download the unit ExceptLog.pas.

Sample output:
This is a sample output after a single line
raise Exception.Create('Here!');
was added to OnFormCreate event of the main form of a project.

New exception:
Delphi exception, type Exception, message: Here!
Exception code: 250477278
Exception flags: 3
Number of parameters: 7
(no debug info) Find error: 7C81EB33
call stack - 0 : Module ELTestU.pas Routine @Eltestu@TForm1@FormCreate Line 27 Find error: 0045A7FA
call stack - 1 : Module Forms.pas Routine @Forms@TCustomForm@DoCreate Line 2648 Find error: 0044FEF3
call stack - 2 : Module Forms.pas Routine @Forms@TCustomForm@AfterConstruction Line 2575 Find error: 0044FB63
call stack - 3 :  Routine @System@@AfterConstruction Find error: 00403EDA
call stack - 4 : Module Forms.pas Routine @Forms@TApplication@CreateForm Line 6946 Find error: 00458DA7
call stack - 5 : Module ELTest.dpr Routine initialization Line 12 Find error: 0045EB64
call stack - 6 : (no debug info) Find error: 7C816D4B
call stack - 7 : (no debug info) Find error: FFFFFFFC