# Setting Crash SDK

IMQA Crash offers various options and enables the user to add custom settings for generating more detailed crash reports.

## 1. Custom crash occurrence <a href="#custom-crash" id="custom-crash"></a>

IMQA Crash Agent can collect the following user-defined errors. You can specify a specific tag and error rank together with the Exception object.

```java
 try {
  ...
} catch (SomeException e) {
  IMQACrashAgent.SendException(e, "ERROR TAG", ErrorRank.Major);
}
```

There are no specific rules for error ranks. Error ranks can be changed according to the app configuration.

<table><thead><tr><th width="218.2087241113939">Rank</th><th width="413.3333333333333">Description</th></tr></thead><tbody><tr><td>ErrorRank.Unhandle</td><td>The default error rank used for an unhandled exception.</td></tr><tr><td>ErrorRank.Critical</td><td>A crash that affects the app significantly.</td></tr><tr><td>ErrorRank.Major</td><td>A crash that affects the app.</td></tr><tr><td>ErrorRank.Minor</td><td>A crash that does not affect the app significantly.</td></tr></tbody></table>

## 2. Custom Web Crash

IMQA WebAgent lets you collect custom errors by specifying the desired error messages for detailed web error analytics.

{% hint style="warning" %}
To collect Webview Crash, you must add CrashWebviewBridge. Please refer to ‘[Android > Setting MPM SDK > WebView HTTP Request > Android Agent Setup](https://docs.imqa.io/imqa-guide/eng/installation-guide/mpm-sdk-setting#android-agent)’.
{% endhint %}

### Create Custom Errors

IMQA WCrash detects and collects user-defined errors.

{% hint style="warning" %}
Different errors but of the same error type are recognized as the same error, which can lead to error accumulation.
{% endhint %}

### Custom Error Messages

You can change the default error messages to any error messages you want and collect them by WebAgent. We recommend specifying several error messages for detailed web error analytics.

{% hint style="warning" %}
If you specify error messages, even errors of the same type will be collected as different errors.
{% endhint %}

{% code title="JS files to collect custom errors" %}

```javascript
...
// When using try-catch
try {
	...
}
catch(e){
	throw new Error("Custom error messages");
}

// When to generate default errors
new Error("Custom error messages");
```

{% endcode %}

You can view web crashes with detailed information in the IMQA WCrash service as shown below.

<figure><img src="https://lh7-us.googleusercontent.com/CW4QD8o6NvrtFpAORvtdBUR8Cxbht1HyBEAsmolCEGG1hyJ13RrUbqbF7KWB62PqL0BPg5hFbHqFjRJYtOaS8E9PVRdiuwIT93NGZN53NRITlp5cVNOei4TgQP5SVOHkUBqVVjL99rlmKYS88hPiS30" alt=""><figcaption></figcaption></figure>

**❶ Caught Error Instance Type**\
Displays the name of the caught error instance of the error if it is generated on a web page.

**❷ Custom Error Message**\
Displays a user-specified message when a specific error-type error is generated.

```javascript
throw new Error("Custom error messages");
```

**❸ Error-type / Code line number**\
You can check the type of webview error and the line number of the error.

<table><thead><tr><th width="179" align="center">Error-type</th><th align="center">Description</th></tr></thead><tbody><tr><td align="center">Error</td><td align="center">This is the error type set by the user.</td></tr><tr><td align="center">EvalError</td><td align="center">This error occurs in <mark style="color:red;">eval()</mark>.</td></tr><tr><td align="center">RangeError</td><td align="center">This error is generated when a variable is outside its valid range.</td></tr><tr><td align="center">ReferenceError</td><td align="center">This error occurs when an incorrect reference is made.</td></tr><tr><td align="center">SyntaxError</td><td align="center">It is an error if incorrect syntax exists.</td></tr><tr><td align="center">TypeError</td><td align="center">If it is not a valid data type, it is a type error.</td></tr><tr><td align="center">URIError</td><td align="center">This error is generated when inappropriate parameters are passed to the <mark style="color:red;">encodeURI()</mark> or <mark style="color:red;">decodeURI()</mark> functions.</td></tr><tr><td align="center">AggregateError</td><td align="center">This is a type of error that wraps multiple errors into one error.</td></tr></tbody></table>

## 3. Registering EventPath <a href="#eventpath" id="eventpath"></a>

EventPath is a function used to check the path of the app launch in the user’s device. The EventPath tracking code should be inserted into the class to use this function. Enter the following details as shown under “STEP” and “LABEL” into the tracking code.

| STEP                                                                                                            | LABEL                                                                                                                      |
| --------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| Get the level of the call stack to collect, and the class name, function name, and call location of that level. | Alias of the collected EventPath. Shows each occurrence location of EventPath as an alias on the crash information window. |

```java
public void onClickSomething() {
      EventPathManager.CreateEventPath(STEP, LABEL);
  }
```

## 4. Registering a custom user ID <a href="#custom-user-id" id="custom-user-id"></a>

You can assign a custom ID to identify a user when a crash occurs. If user information is registered, the user information will also be displayed in crash occurrence information.

<table><thead><tr><th width="185.56548708822163">Class Name</th><th>Method Name</th><th>Description</th></tr></thead><tbody><tr><td>IdentifierCollector</td><td>setUserId(STRING)</td><td>Register a user ID.</td></tr><tr><td>IdentifierCollector</td><td>setUserName(STRING)</td><td>Register a user name.</td></tr><tr><td>IdentifierCollector</td><td>setUserMail(STRING)</td><td>Register a user email.</td></tr></tbody></table>

```javascript
IdentifierCollector.setUserId("10"); // Register a user ID.
IdentifierCollector.setUserName("My User Name"); // Register a user name.
IdentifierCollector.setUserMail("My User Email"); // Register a user email.
```

## 5. Registering a custom user log/key <a href="#custom-user-log-key" id="custom-user-log-key"></a>

The developer can manually leave additional logs before a crash occurs (up to 100 logs.)

<table><thead><tr><th width="219">Class Name</th><th width="174.33333333333331">Method Name</th><th>Description</th></tr></thead><tbody><tr><td>CustomLogCollector</td><td>log(STRING)</td><td>Leaves the log as a plain string.</td></tr><tr><td>CustomLogCollector</td><td>log(KEY, VALUE)</td><td>Leaves the log in the form of key:value.</td></tr></tbody></table>

```javascript
CustomLogCollector.log("test log"); // Leaves the log as a plain string.
CustomKeyCollector.log("My Key", "My Log"); // Leaves the log in the form of key:value.
```

## 6. Adding initialization options <a href="#option" id="option"></a>

You can specify options when initializing IMQAController. You can change the IMQA Crash mode using parameters or options.

<table><thead><tr><th width="147.46004682530355">Class Name</th><th width="244">Method Name</th><th>Description</th></tr></thead><tbody><tr><td>IMQAOption</td><td>setDirectUploadFlag(BOOL)</td><td>Sets upload mode. If set to false, it will also work in debug mode.</td></tr><tr><td>IMQAOption</td><td>setPrintLog(BOOL)</td><td>Sets whether to output the log. If set to true, IMQA logs are output.</td></tr><tr><td>IMQAOption</td><td>setAnrOn(BOOL)</td><td>Sets whether to monitor ANR. If set to false, ANR will be excluded from crash collection.</td></tr><tr><td>IMQAOption</td><td>setAnrTimeoutIntercal(int)</td><td>Sets the time when ANR timeout occurs (in milliseconds.)</td></tr></tbody></table>

{% code title="MyApplication.java" %}

```java
@Override
public void onCreate() {
    super.onCreate();
      
    io.imqa.core.IMQAOption imqaOption = new io.imqa.core.IMQAOption();

    /*  
     * Default value: true
     * Sets whether to collect ANR information. 
     * true: Monitors the ANR occurrence status.
     * false: Stops monitoring ANR occurrence.
    */
    imqaOption.setAnrOn(false);


    /*
     * Default value : 5000
     * anrTimeoutInveral : Sets the time when ANR timeout occurs (in milliseconds.)
     */
    imqaOption.setAnrTimeoutInterval(5000);


   /*
     * Default value : false
     * Sets whether to output the log. 
     * true: Outputs the IMQA Crash log.
    */
    imqaOption.setPrintCrashLog(true);

    /*
     * Default value : true
     * Uploads collected crash information as soon as the crash occurs.
     * true: Uploads as soon as the crash occurs.
     * false: Uploads when executing again after saving.
    */
    imqaOption.setCrashDirectUploadFlag(false);

    /*
     * Default value : false
     * Set the compression algorithm.
     * true : Using Zstandard (Zstd).
     * false : Using gzip algorithm
    */
    imqaOption.setCompressZstd(true);

    /*
     * Default value : 'https://collector.imqa.io'
     * Sets the crash server URL.
     * String: Server information
     */
    imqaOption.setCrashServerUrl('https://collector.imqa.io');

    io.imqa.crash.IMQACrashAgent.InitializeAndStartSession(
        this, // Application Context
        BuildConfig.FLAVOR, // Project Flavor Setting
        "PROJECT_KEY",  // Issued project key
        imqaOption // Add an object when the option is set.
    );
}
```

{% endcode %}


---

# 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://docs.imqa.io/imqa-guide/eng/installation-guide/android/crash-sdk-setting.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.
