Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples to use the new recordException overload. #596

Merged
merged 15 commits into from
Jan 20, 2025
Merged
2 changes: 1 addition & 1 deletion crashlytics/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies {
implementation("androidx.appcompat:appcompat:1.7.0")

// Import the BoM for the Firebase platform
implementation(platform("com.google.firebase:firebase-bom:33.6.0"))
implementation(platform("com.google.firebase:firebase-bom:33.8.0"))

// Add the dependencies for the Crashlytics and Analytics libraries
// When using the BoM, you don't specify versions in Firebase library dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.view.ViewGroup;
import android.widget.Button;

import com.google.firebase.crashlytics.CustomKeysAndValues;
import com.google.firebase.crashlytics.FirebaseCrashlytics;

public class MainActivity extends AppCompatActivity {
Expand Down Expand Up @@ -80,6 +81,22 @@ public void logCaughtEx() {
// [END crash_log_caught_ex]
}

public void logCaughtExWithCustomKeys() {
// [START crash_log_caught_ex_custom_keys]
try {
methodThatThrows();
} catch (Exception e) {
CustomKeysAndValues keysAndValues = new CustomKeysAndValues.Builder()
.putString("string key", "string value")
.putBoolean("boolean key", true)
.putFloat("float key", Float.MAX_VALUE)
.build();
FirebaseCrashlytics.getInstance().recordException(e, keysAndValues);
// handle your exception here
}
// [END crash_log_caught_ex_custom_keys]
}

public void forceACrash() {
// [START crash_force_crash]
Button crashButton = new Button(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.view.ViewGroup
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import com.google.firebase.crashlytics.crashlytics
import com.google.firebase.crashlytics.recordException
import com.google.firebase.crashlytics.setCustomKeys
import com.google.firebase.Firebase

Expand Down Expand Up @@ -77,6 +78,21 @@ class MainActivity : AppCompatActivity() {
// [END crash_log_caught_ex]
}

fun logCaughtExWithCustomKeys() {
// [START crash_log_caught_ex_custom_keys]
try {
methodThatThrows()
} catch (e: Exception) {
Firebase.crashlytics.recordException(e) {
key("string key", "string value")
key("boolean key", true)
key("float key", Float.MAX_VALUE)
}
// handle your exception here
}
// [END crash_log_caught_ex_custom_keys]
}

fun forceACrash() {
// [START crash_force_crash]
val crashButton = Button(this)
Expand Down
Loading