# Class CrashProtection

java.lang.Object
com.codename1.crash.CrashProtection

public final class CrashProtection extends Object

Crash protection: captures unhandled exceptions, scrubs PII, persists each crash to `Storage` immediately, and uploads to the Codename One cloud crash service when enabled.

Quick start -- call from your `Lifecycle.init` (NOT from `start`, which runs on every resume):

    CrashProtection.install();
    CrashProtection.setEnabled(true);

`install()` is idempotent and wires the EDT error handler, the platform native crash handler, and the native log capture. It also replays any crash data persisted by the previous run (Java-side failures buffered in `Storage`, plus native-layer crash records written by the platform crash handler before the process died).

`setEnabled` defaults to `false`, so no data leaves the device until the developer explicitly enables uploads.

Pluggable PII scrubbing: override `PiiScrubber` and register your subclass via `setScrubber(PiiScrubber)` to extend the default redaction rules. The default scrubber masks the local part of email addresses (keeping the first three characters and the full domain) and replaces runs of six or more digits with `[num]`.

The endpoint URL is fixed and cannot be modified by the application. Crash uploads are accepted only for Pro-tier (or higher) accounts for builds produced by the Codename One cloud build server within the last 30 days; out-of-tier or stale builds are silently dropped by the server.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `capture(Throwable t)`
  Manually report an exception.
  `static PiiScrubber`
  `getScrubber()`
  `static void`
  `install()`
  Installs the crash protection hooks.
  `static boolean`
  `isEnabled()`
  `static void`
  `setEnabled(boolean enabled)`
  Enables or disables crash uploads.
  `static void`
  `setScrubber(PiiScrubber s)`
  Replaces the active PII scrubber.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### install

    public static void install()

    Installs the crash protection hooks. Idempotent: calling more than once has no effect. Does nothing on the simulator (matches the legacy `Log.bindCrashProtection` behaviour) or when crash protection has been disabled for the current platform via the `codename1.crashProtection.<platform>.enabled` build property (see `isPlatformDisabled()`).

    Side effect: any crashes previously persisted to storage but not yet uploaded will be drained in the background if uploads are currently enabled.

  - ### isEnabled

    public static boolean isEnabled()
    Returns:
      `true` if crash uploads are enabled. Default is `false`.

  - ### setEnabled

    public static void setEnabled(boolean enabled)
    Enables or disables crash uploads. When transitioning from off to on, any crashes buffered in storage are drained in the background. The toggle persists across launches.

  - ### setScrubber

    public static void setScrubber(PiiScrubber s)
    Replaces the active PII scrubber. Subclass `PiiScrubber` to extend or replace the default redaction rules.

  - ### getScrubber

    public static PiiScrubber getScrubber()

  - ### capture

    public static void capture(Throwable t)
    Manually report an exception. The crash is persisted to storage first and then uploaded if uploads are enabled. Stack frames are captured from the throwable.