Click here to Skip to main content
15,306,585 members
Articles / Web Development / HTML
Posted 29 Jun 2006


293 bookmarked

Catch All Bugs with BugTrap!

Rate me:
Please Sign up or sign in to vote.
4.32/5 (83 votes)
31 Jan 2009MIT5 min read
A tool that can catch unhandled errors and exceptions, and deliver error reports to remote support servers

What's new in this version?

  • 64 bit support - now BugTrap natively supports Win64
  • Multi-monitor support - BugTrap may capture screenshots from several monitors
  • Other enhancements - Tons of features/options added since last update. See app history for details


Some time ago, I was working on a multi-tier application with quite complex logic. The application was handling medical information, and it was important to correctly synchronize data under all circumstances. I put extra code to make the application as stable as possible, and added automatic backups and self-recovery. Do you think it solved all problems?

No, I was still searching for a tool to handle problems, seen by customers, remotely. How could I assist them and debug the problem if I lived on the other side of the globe? Eventually, I found this excellent Jim Crafton article about a tool capable of intercepting unhandled errors. That was a solution!

Unfortunately, the original black-box was not customizable, it didn't support mini-dump files or Unicode strings, and it didn't have any server. In spite of these limitations, it was an excellent starting point because I knew exactly what kind of a tool I wanted. I started working on my own tool in the hope of making it flexible and customizable, and a powerful solution.


Usually, it's very frustrating to receive a message from your customer saying that your program doesn't work. Most users may not let you know what's incorrect in your application and which piece of code went wrong. Windows has a built-in handler for unhandled errors, however, this default handler might be useless when errors happen on the customer side, because you rarely want to send your error report to Microsoft:

Default Win32/64 error handler

BugTrap solves this problem by overriding the default error handler. BugTrap gathers error details such as address, call stack, and the computer environment. It's also possible to add an arbitrary number of custom log files, with additional information on the default error report, using built-in or external logging functions.

BugTrap may save error reports on the disk, or automatically deliver error reports to the developer's computer by e-mail, over HTTP, or through a fast low-level TCP-based network protocol. The BugTrap server automatically manages the error reports repository, and notifies developers about any new errors.

Network diagram

BugTrap stores error descriptions in log and mini-dump files. Mini-dump files may be opened in Microsoft Visual Studio .NET and in WinDbg. The BugTrap package also includes a CrashExplorer utility that can extract symbolic information from MAP and PDB files. There is a special BugTrap version for .NET applications (currently under development).

Simplified dialog

Dialog with error details

Preview dialog

All details are available in the BugTrap documentation. The documentation is also included as part of the Setup. If you like to know how BugTrap works, you may read these articles:

Adding BugTrap Support to Win32/64 Applications

BugTrap is redistributed as a dynamic-link library (DLL). Two versions of the BugTrap DLL are available: the ANSI version, and the Unicode version.

DLL name Character encoding
BugTrap.dll ANSI multi-byte character strings
BugTrapU.dll Unicode strings

The code below adds BugTrap support to Win32/64 applications:

#include "BugTrap.h"

#pragma comment(lib, "BugTrap.lib")      // Link to ANSI DLL
// #pragma comment(lib, "BugTrapU.lib")  // Link to Unicode DLL

static void SetupExceptionHandler()
    BT_SetAppName(_T("Your application name"));
    BT_SetSupportServer(_T("localhost"), 9999);

The SetupExceptionHandler() function may be called from InitInstance() or main(), depending on the type of your application.

When your application experiences a problem, the user is prompted by BugTrap to submit an error report to the BugTrap server. The error report includes many details of the user environment. The report also includes a complete stack trace for the call that caused a problem.

With BugTrap, you can debug the problem using two different approaches.

1. You can open post-mortem mini-dump files in Visual Studio:

Minidump file in Visual Studio

2. You can use the built-in utility CrashExplorer:

When BugTrap is building stack traces, it searches for the PDB file – a file that holds debugging information. If this file is available, BugTrap is able to show function names and line numbers next to each address. Obviously, the PDB file makes the stack trace much nicer, but most developers prefer not to distribute PDB files to end users because PDB files could simplify program reverse engineering.

Therefore, BugTrap doesn't require PDB files on user computers. Instead, it saves raw function addresses to the log:

Dialog with no source information

So, the end user doesn't have any clue what's behind these hexadecimal numbers.

CrashExplorer reverts back all functions names and line numbers based on the PDB/MAP file and addresses in a log:

CrashExplorer restores function names and lines numbers from MAP or PDB file

Adding BugTrap Support to .NET Applications

.NET version of BugTrap is redistributed as managed library: BugTrapN.dll. This DLL consists of managed and unmanaged code. Such design lets BugTrap support pure managed .NET assemblies as well as mixed C++ assemblies that could throw managed .NET exceptions and native Win32/64 exceptions.

BugTrap for .NET exposes both managed and unmanaged (native) interfaces. Managed interface is accessible from C# or VB.NET code:

ExceptionHandler.AppName = "Your application name";
ExceptionHandler.Flags = FlagsType.DetailedMode | FlagsType.EditMail;
ExceptionHandler.DumpType = MinidumpType.NoDump;
ExceptionHandler.SupportEMail = "";
ExceptionHandler.SupportURL = "";
ExceptionHandler.SupportHost = "localhost";
ExceptionHandler.SupportPort = 9999;

Unmanaged interface is accessible from native Win32/64 code and was discussed earlier. It is possible to use any interface or even both interfaces in the same application.


I periodically fix errors and add new features. This frequency of such updates depends on your feedback. You may check for the most recent updates. All major updates are submitted to The Code Project.

Building Notes

Most developers may go ahead and download the Setup - it installs all necessary files and components. However, some professionals enjoy building all components from scratch. Those developers may download BugTrap source code from here.

I have been trying to make BugTrap DLL as compact as possible. Therefore BugTrap DLL does not use MFC/ATL/WTL. I have been using pure C and C++. In particular, you will find several classes from my own library: collection classes, IO streams, built-in XML parser, etc. BugTrap DLL depends on zlib. I have included it in the archive to simplify building.

CrashExplorer depends on STL, Boost and WTL. Both libraries must be pre-installed on your computer.

Thank you!

I appreciate support, help, contributions, and even simple feedback that I am getting from many of you. BugTrap could not be in a position to meet the demands of modern software without this.

That's it! Happy bug-trapping ;-)


This article, along with any associated source code and files, is licensed under The MIT License


About the Author

Maksim Pyatkovskiy
United States United States
No Biography provided

Comments and Discussions

QuestionHi I'm trying to generate .dmp file but it doesn't seem to be created Pin
Member 1250608829-Mar-17 21:36
MemberMember 1250608829-Mar-17 21:36 
QuestionHow about C++ Visual Studio 2003 Pin
TEjoNavy31-Mar-16 9:30
MemberTEjoNavy31-Mar-16 9:30 
Questionlinux alternative? Pin
dn_lillh11-Feb-16 20:53
Memberdn_lillh11-Feb-16 20:53 
Brian Chavez8-Oct-15 13:05
MemberBrian Chavez8-Oct-15 13:05 
QuestionVC2008 Qt4.8.5 - Stacktrace can't be rebuild when given crashreport is created on other machine than the build machine Pin
medion32x2-Jul-14 23:33
Membermedion32x2-Jul-14 23:33 
QuestionIs it possible to use BugTrap with visual basic 6.0? Pin
duckking16-Mar-14 5:22
Memberduckking16-Mar-14 5:22 
QuestionHow to disable BugTrap server option? Pin
thomas70818-Sep-13 7:31
Memberthomas70818-Sep-13 7:31 
QuestionCan anybody please send me the source code Pin
Member 810403821-Apr-13 20:04
MemberMember 810403821-Apr-13 20:04 
AnswerRe: Can anybody please send me the source code Pin
abakanov17-May-13 2:33
Memberabakanov17-May-13 2:33 
QuestionCan anybody please send me the source code Pin
TPJ2-Apr-13 1:42
MemberTPJ2-Apr-13 1:42 
AnswerRe: Can anybody please send me the source code Pin
Brian Chavez8-Oct-15 11:50
MemberBrian Chavez8-Oct-15 11:50 
QuestionCould you please send me th source code? Pin
asterx923-Jan-13 22:13
Memberasterx923-Jan-13 22:13 
AnswerRe: Could you please send me th source code? Pin
Brian Chavez8-Oct-15 11:52
MemberBrian Chavez8-Oct-15 11:52 
Questionmirrored source code (older version) Pin
Member 83188774-Jan-13 3:50
MemberMember 83188774-Jan-13 3:50 
QuestionCan you please send me source code? Pin
Member 83188773-Jan-13 5:01
MemberMember 83188773-Jan-13 5:01 
QuestionCould you please send me th source code? Pin
Rain_Boy31-Dec-12 13:55
MemberRain_Boy31-Dec-12 13:55 
QuestionCan you please send me source code? Pin
cocasema12-Dec-12 9:05
Membercocasema12-Dec-12 9:05 
QuestionPlease send to me source code. Pin
Member 205488228-Nov-12 23:21
MemberMember 205488228-Nov-12 23:21 
QuestionHow do I Install BugTrapWebServer On Windows Server 2008? Pin
pinchen13-Nov-12 20:40
Memberpinchen13-Nov-12 20:40 
QuestionWhether to allow the web server automatically generates the corresponding version number data folder? Pin
pinchen15-Oct-12 0:41
Memberpinchen15-Oct-12 0:41 
QuestionCould someone please send me the source code too? Pin
liyubo360323717-Sep-12 21:27
Memberliyubo360323717-Sep-12 21:27 
QuestionPlease send to me source code. Pin
David Hellier11-Sep-12 3:09
MemberDavid Hellier11-Sep-12 3:09 
AnswerRe: Please send to me source code. Pin
Member 459196212-Sep-12 2:28
MemberMember 459196212-Sep-12 2:28 
Questionplease sent to me a bugtrap's source code zip file Pin
nguyenle36831-Jul-12 21:33
Membernguyenle36831-Jul-12 21:33 
QuestionName of .zip-file Pin
Gisle Vanem19-Jul-12 10:19
MemberGisle Vanem19-Jul-12 10:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.