# 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: 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.aeternity.com/developer-documentation/aepp-sdk-js/docs/guides/error-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.
