Java

๐Ÿ— Installation

Install com.bugsplat from Maven Central.

Maven

<dependency>
    <groupId>com.bugsplat</groupId>
    <artifactId>bugsplat-java</artifactId>
    <version>0.0.0</version>
</dependency>

Gradle

implementation("com.bugsplat:bugsplat-java:0.0.0")

โš™๏ธ Configuration

After you've installed the SDK from Maven, add an import statement for com.bugsplat.BugSplat:

import com.bugsplat.BugSplat;

Call BugSplat.init providing it your database, application, and version. It's best to do this at the entry point of your application. Several defaults can be provided to BugSplat. You can provide default values for things such as description, email, key, notes, user and additional file attachments.

BugSplat.init("Fred", "MyJavaCrasherConsole", "1.0");
BugSplat.setDescription("Please enter a description");
BugSplat.setEmail("fred@bugsplat.com");
BugSplat.setNotes("bobby testing notes");
BugSplat.setKey("en-US");
BugSplat.setUser("Fred");
BugSplat.addAdditionalFile(new File("file.txt").getAbsolutePath());

For servers, console applications, or applications where you don't want to show the report dialog, call BugSplat.setQuietMode to prevent the BugSplat dialog from appearing.

BugSplat.setQuietMode(true);

Wrap your application in a try/catch block and call BugSplat.handleException in the catch block. This will post the exception to BugSplat.

try {
    throw new Exception("BugSplat rocks!");
} catch (Exception ex) {
    Bugsplat.handleException(ex);
}

If your application uses threads, add a call to BugSplat.handleException in uncaughtException to post a report to BugSplat before the thread is terminated.

class MyThreadGroup extends ThreadGroup {
  public MyThreadGroup (String s) {
      super(s);
  }

  public void uncaughtException(Thread thread, Throwable throwable) {
      BugSplat.handleException(new Exception(throwable));                     
  }
}

๐Ÿ—บ๏ธ Samples

This repo includes sample projects that demonstrate how to integrate bugsplat-java. Please review the my-java-crasher and my-java-crasher-console folders for more a sample implementation. To run the sample projects, clone this repo and open it in either IntelliJ IDEA or VS Code.

โœ… Verification

Once you've generated an exception, navigate to the BugSplat Dashboard and ensure you have to correct database selected in the dropdown menu. You should see a new report under the Recent Crashes section:

Click the link in the ID column to see details about the report:

Thatโ€™s it! Your application is now configured to post reports to BugSplat.

Last updated