> For the complete documentation index, see [llms.txt](https://dexiejs.typogram.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dexiejs.typogram.co/dexieerror/dexie.subtransactionerror.md).

# Dexie.SubTransactionError

#### Inheritance Hierarchy

* [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
  * Dexie.DexieError
    * Dexie.SubTransactionError

#### Description

A call to db.transaction() with a mode or set of tables that was not compatible with the currently ongoing transaction. For example:

```javascript
db.transaction('r', db.friends, ()=> {
    return db.transaction('rw', db.friends, db.pets, ()=> {

    }).catch(e => {
        // e will be SubTransactionError for two reasons:
        // 1. Parent transaction is readonly.
        // 2. Parent transaction does not include db.pets.
    })
});
```

To work around this error, make sure that the parent transaction includes all tables that subtransactions may include and that if subtransactions require 'rw' mode, use 'rw' mode also in parent transactions.

If you didn't have a parent transaction, but your transaction was initiated in your Collection.each() or Collection.modify() callback, you should surround the call to Collection.each() / Collection.modify() with a transaction block, including the correct mode and tables to include.

#### Sample using Promise.catch()

```javascript
doSomeDatabaseWork().then(result => {
    // Success
}).catch('SubTransactionError', e => {
    // Failed with SubTransactionError
    console.error ("SubTransaction error: " + e.message);
}).catch(Error, e => {
    // Any other error derived from standard Error
    console.error ("Error: " + e.message);
}).catch(e => {
    // Other error such as a string was thrown
    console.error (e);
});
```

#### Sample: switch(error.name)

```javascript
db.on('error', function (error) {
    switch (error.name) {
        // errnames.SubTransaction ==="SubTransactionError"
        case Dexie.errnames.SubTransaction:
            console.error ("SubTransaction error");
            break;
        default:
            console.error ("error: " + e);
    }
});
```

#### Properties

| name    | Will always be Dexie.errnames.SubTransaction === "SubTransactionError"             |
| ------- | ---------------------------------------------------------------------------------- |
| message | Detailed message                                                                   |
| inner?  | Inner exception instance (if any)                                                  |
| stack   | Can be present if the error was thrown. If signaled, there wont be any call stack. |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://dexiejs.typogram.co/dexieerror/dexie.subtransactionerror.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.
