# 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()
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://adityabavadekar.gitbook.io/pinlog-docs/exception-handling.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
