> For the complete documentation index, see [llms.txt](https://adityabavadekar.gitbook.io/pinlog-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://adityabavadekar.gitbook.io/pinlog-docs/exception-handling.md).

# Exception Handling

That means whenever your app crashes, PinLog calls a method that creates a so called crash report and open email app with that crash report attached to it. You can provide the `message` ,`emailAddresses` and the `subject` for the Email to PinLog.

{% hint style="warning" %}
Warning : PinLog force closes the application after a crash to avoid ANRs (Application Not Responding) errors
{% endhint %}

{% code title="App.kt" %}

```kotlin
// After initialising PinLog
PinLog.setupExceptionHandler(arrayOf("example@gmail.com"), 
"You can add additional comments in this email which may help us a lot.",
"Sorry MyApplication crashed, we will try better next time.")
```

{% endcode %}

## Adding custom data to the crash report.

If you want to add custom data to the crash report you can add it like this from anywhere.

```kotlin
PinLog.CustomLogFileData().put("MyFirstCustomData", "Hello, World")
PinLog.CustomLogFileData().put("MySecodeCustomData", "Welcome to the World")
```

## Creating a report without Exception Handler

To create a report use the below method.&#x20;

> This method creates a report that includes data from your `CustomData`, your `PinLogs`, `applicationInfo`, `BuildConfigClass` (if was provided while initialisation) and the application default `Preferences`, .

{% hint style="info" %}
**Note :** The report returned is a `JSONObject` whose key can be retrieved from `PinLog.CrashReporter.CrashDataKeys` object.
{% endhint %}

```kotlin
try {

    //Do some stuff that might throw exceptions.
    
}catch(e:Exception){
    val myReport : JSONObject = PinLog.createReport(Thread.currentThread(),e)
    //Do whatever you want with the Report.
}
```

## Disabling PinLog Exception Handler

If you want to disable the PinLog exception handler after you have set it, you can call this method.

```kotlin
PinLog.disablePinLogExceptionHandler()
```
