BugSplat .NET  3.6.0.0
BugSplat .NET API reference
BugSplat .NET Documentation

Integrating BugSplat crash reporting into your .NET application is easy! The following example code is from the myDotNetCrasher application:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
// Notes:
// This sample project illustrates how to capture crashes (unhandled exceptions) in a managed application using BugSplat.
//
// The shared sample database, 'Fred', is used in this example.
// You may view crashes for the Fred account by logging in at https://www.bugsplat.com:
// Account (Email Address): Fred
// Password: Flintstone
//
// In order to assure that crashes sent to the BugSplat website yield exception stack traces with file/line # information,
// just rebuild this project. A Visual Studio post build event is configured to send the resulting .exe and .pdb files
// to BugSplat via the SendPdbs utility. If you wish to use your own account and database, you will need to modify the post build
// event accordingly. If you do not care about file/line # info or for any reason you do not want to send these files,
// simply disable the post build event.
//
// Important: if you would like to run the program from Visual Studio, disable the "Just My Code" option
// so the debugger will not interfere with the BugSplat exception handlers.
// To enable or disable Just My Code debugging:
// On the Tools menu, choose Options.
// In the Options dialog box, open the Debugging node and then choose General.
// Select or clear Enable Just My Code.
//
// More information is available online at https://www.bugsplat.com
namespace myDotNetCrasher
{
static class Program
{
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 mainForm = new Form1();
// Initialize BugSplat with our database, application and version strings
string Database = "Fred";
string App = Assembly.GetExecutingAssembly().GetName().Name;
string Version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
BugSplat.CrashReporter.Init(Database, App, Version);
// Let BugSplat know what events to handle
System.AppDomain.CurrentDomain.UnhandledException += BugSplat.CrashReporter.AppDomainUnhandledExceptionHandler;
System.Windows.Forms.Application.ThreadException += BugSplat.CrashReporter.ApplicationThreadException;
//System.Threading.Tasks.TaskScheduler.UnobservedTaskException += BugSplat.CrashReporter.TaskSchedulerUnobservedTaskExceptionHandler;
// Add an application event handler
if (args.Length > 0 && args[0] == "/crash")
{
throw new Exception("intentional crash");
}
Application.Run(mainForm);
}
// Called from the BugSplat Event
public static void OnBugSplatEvent(Exception e)
{
// An application specfic action can be taken here. For our example program nothing happens.
//MessageBox.Show("BugSplat Event", "OnBugSplatEvent", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop);
}
}
}
using System;
using System.IO;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using System.Collections.Generic;
using ManagedTestDll;
namespace myDotNetCrasher
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void MemoryAccessViolationButton_Click(object sender, System.EventArgs e)
{
Object o = null;
MessageBox.Show(o.ToString());
}
private void DivideByZeroButton_Click(object sender, System.EventArgs e)
{
ErrorExamples ex = new ErrorExamples();
ex.IntDivideByZero();
}
private void ManagedThreadExceptionButton_Click(object sender, System.EventArgs e)
{
ErrorExamples y = new ErrorExamples();
Thread t = new Thread(
new ThreadStart(y.IntDivideByZero));
t.Start();
t.Join();
}
private void ManagedDllExceptionButton_Click(object sender, EventArgs e)
{
ManagedTestDll.Test.MemoryException();
}
private void NativeDllExceptionButton_Click(object sender, EventArgs e)
{
NativeTestDll.MemoryException();
}
// An example of catching an exception, and then reporting it with BugSplat.createReport();
private void CatchExceptionButton_Click(object sender, System.EventArgs e)
{
try
{
Object o = null;
MessageBox.Show(o.ToString());
}
catch (Exception excpt)
{
}
}
private void SendAdditionalFilesButton_Click(object sender, System.EventArgs e)
{
string tmpName = Path.GetTempFileName();
tmpName = Path.ChangeExtension(tmpName, ".xml");
StreamWriter sw = new StreamWriter(tmpName);
sw.WriteLine("<tag>This is a test file. Apps can put anything here.</tag>");
sw.Close();
Object o = null;
MessageBox.Show(o.ToString());
}
private void InnerExceptionButton_Click(object sender, System.EventArgs e)
{
FuncLevel1();
}
private void FuncLevel1()
{
FuncLevel2();
}
private void FuncLevel2()
{
FuncLevel3();
}
private void FuncLevel3()
{
try
{
FuncLevel4();
}
catch (Exception e)
{
throw new Exception("Test Outer Exception", e);
}
}
private void FuncLevel4()
{
throw new Exception("Test Exception Thrown by sample code");
}
private void exitButton_Click(object sender, EventArgs e)
{
Application.Exit();
}
private async void unwatchedExceptionButton_Click(object sender, EventArgs e)
{
Task[] TaskArray = new Task[] { run() };
var tasks = new HashSet<Task>(TaskArray);
tasks.Remove(await Task.WhenAny(tasks));
GC.Collect();
GC.WaitForPendingFinalizers();
}
public async Task<int> run()
{
return await Task.Run(() => {
throw new Exception("broke");
return 0;
});
}
}
internal class ErrorExamples
{
public void IntDivideByZero()
{
int x, y;
x = 5;
y = 0;
int nRes = x / y;
}
}
internal class NativeTestDll
{
[DllImport("NativeTestDll.dll")]
public static extern void MemoryException();
}
}