<VersionWarning version="0.1" />

# Error Handling

Similarly to how [error handling in viem works](https://viem.sh/docs/error-handling), every module in permissionless.js exports an accompanying error type which you can use to strongly type your `catch` statements.

These types come in the form of `<Module>ErrorType`. For example, the `estimateUserOperationGas` action exports a `EstimateUserOperationGasErrorType` type.

Unfortunately, [TypeScript doesn't have an abstraction for typed exceptions](https://github.com/microsoft/TypeScript/issues/13219), so the most pragmatic & vanilla approach would be to explicitly cast error types in the `catch` statement.

:::code-group
```ts [example.ts] twoslash
// @noErrors
// @filename: client.ts
import { createBundlerClient } from 'permissionless'
import { http } from "viem"
import { mainnet } from 'viem/chains'

export const bundlerClient = createBundlerClient({
  chain: mainnet,
  transport: http(),
  entryPoint: ENTRYPOINT_ADDRESS_V06,
})
// @filename: index.ts
// ---cut---
import { 
    type EstimateUserOperationGasErrorType, 
    type SenderAlreadyDeployedError,
    ENTRYPOINT_ADDRESS_V07
} from 'permissionless'
import { bundlerClient } from './client'

try {
    const estimateResult = await bundlerClient.estimateUserOperationGas({
        userOperation,
    })
} catch (e) {
    const estimationError = e as EstimateUserOperationGasErrorType<"v0.7">
    estimationError.name
    //              ^?



    const error = estimationError.walk(
        (e) => e instanceof SenderAlreadyDeployedError,
    )
    if (error instanceof SenderAlreadyDeployedError) {
        error.name
        //     ^?


    }
}
```

```ts [client.ts]
import { createBundlerClient } from 'permissionless'
import { http } from "viem"
import { mainnet } from 'viem/chains'

export const bundlerClient = createBundlerClient({
  chain: mainnet,
  transport: http(),
  entryPoint: ENTRYPOINT_ADDRESS_V06,
})
```
:::
