> For the complete documentation index, see [llms.txt](https://docs.aeternity.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aeternity.com/developer-documentation/aepp-sdk-js/docs/guides/error-handling.md).

# Error Handling

This guide shows you how to handle errors originating from the SDK. SDK by default exports the following error classes from file [errors.ts](https://github.com/aeternity/aepp-sdk-js/blob/1cd128798018d98bdd41eff9104442b44b385d46/src/utils/errors.ts)

## Error Hierarchy

```
BaseError
├── ArgumentError
├── IllegalArgumentError
├── ArgumentCountMismatchError
├── InsufficientBalanceError
├── MissingParamError
├── NoSerializerFoundError
├── RequestTimedOutError
├── TxTimedOutError
├── TypeError
├── UnsupportedPlatformError
├── UnsupportedProtocolError
├── NotImplementedError
├── UnsupportedVersionError
├── LogicError
│
├── InternalError
│   └── UnexpectedTsError
│
├── AccountError
│   └── UnavailableAccountError
│
├── AensError
│   ├── AensPointerContextError
│   ├── InsufficientNameFeeError
│   └── InvalidAensNameError
│
├── AeppError
│   ├── InvalidRpcMessageError
│   ├── MissingCallbackError
│   ├── UnAuthorizedAccountError
│   ├── UnknownRpcClientError
│   └── UnsubscribedAccountError
│
├── ChannelError
│   ├── ChannelCallError
│   ├── ChannelConnectionError
│   ├── ChannelPingTimedOutError
│   ├── UnexpectedChannelMessageError
│   ├── ChannelIncomingMessageError
│   └── UnknownChannelStateError
│
├── CompilerError
│   └── InvalidAuthDataError
│
├── ContractError
│   ├── BytecodeMismatchError
│   ├── DuplicateContractError
│   ├── InactiveContractError
│   ├── InvalidMethodInvocationError
│   ├── MissingContractAddressError
│   ├── MissingContractDefError
│   ├── MissingFunctionNameError
│   ├── NodeInvocationError
│   ├── NoSuchContractFunctionError
│   ├── NotPayableFunctionError
│   ├── MissingEventDefinitionError
│   └── AmbiguousEventDefinitionError
│
├── CryptographyError
│   ├── InvalidChecksumError
│   ├── MerkleTreeHashMismatchError
│   ├── MissingNodeInTreeError
│   ├── UnknownNodeLengthError
│   └── UnknownPathNibbleError
│
├── NodeError
│   ├── DuplicateNodeError
│   └── NodeNotFoundError
│
├── TransactionError
│   ├── DecodeError
│   ├── PayloadLengthError
│   ├── DryRunError
│   ├── IllegalBidFeeError
│   ├── InvalidSignatureError
│   ├── InvalidTxError
│   ├── PrefixNotFoundError
│   ├── SchemaNotFoundError
│   ├── TagNotFoundError
│   └── TxNotInChainError
│
├── WalletError
│   ├── AlreadyConnectedError
│   ├── NoWalletConnectedError
│   └── RpcConnectionError
│
├── RpcError
│   ├── RpcInvalidTransactionError
│   ├── RpcRejectedByUserError
│   ├── RpcUnsupportedProtocolError
│   ├── RpcConnectionDenyError
│   ├── RpcNotAuthorizeError
│   ├── RpcPermissionDenyError
│   └── RpcInternalError
```

## Usage

```js
// import required error classes
import {
  AeSdk,
  Node,
  AccountMemory,
  ArgumentError,
  InvalidAensNameError,
} from '@aeternity/aepp-sdk';

// setup
const payerAccount = AccountMemory.generate();
const newUserAccount = AccountMemory.generate();
const node = new Node('https://testnet.aeternity.io');
const aeSdk = new AeSdk({
  nodes: [{ name: 'testnet', instance: node }],
  accounts: [payerAccount, newUserAccount],
});

// catch exceptions
try {
  const spendTxResult = await aeSdk.spend(-1, newUserAccount.address, { onAccount: payerAccount });
} catch (err) {
  if (err instanceof ArgumentError) {
    console.log(`Amount specified is not valid, ${err.message}`);
  } else if (err instanceof InvalidAensNameError) {
    console.log(`Address specified is not valid, ${err.message}`);
  }
}

// using generic error classes
import { AensError, TransactionError, BaseError } from '@aeternity/aepp-sdk';

try {
  const spendTxResult = await aeSdk.spend(1, 'ak_2tv', { onAccount: payerAccount });
} catch (err) {
  if (err instanceof AensError) {
    // address or AENS related errors
  } else if (err instanceof TransactionError) {
    // transaction errors
  } else if (err instanceof BaseError) {
    // match any errors from the SDK
  }
}
```


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.aeternity.com/developer-documentation/aepp-sdk-js/docs/guides/error-handling.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
