---
title: "cancelTunnelWithError(_:)"
framework: networkextension
role: symbol
role_heading: Instance Method
path: "networkextension/nepackettunnelprovider/canceltunnelwitherror(_:)"
---

# cancelTunnelWithError(_:)

Stop the network tunnel from the Packet Tunnel Provider.

## Declaration

```swift
func cancelTunnelWithError(_ error: (any Error)?)
```

## Parameters

- `error`: An doc://com.apple.documentation/documentation/Foundation/NSError object containing the error that caused the tunnel to be stopped. The domain and code of this NSError object is defined by the caller.

## Discussion

Discussion The Packet Tunnel Provider should call this method when an unrecoverable error occurs, such as the tunnel server going down or the VPN authentication session expiring.

## See Also

### Managing the tunnel life cycle

- [startTunnel(options:completionHandler:)](networkextension/nepackettunnelprovider/starttunnel(options:completionhandler:).md)
- [stopTunnel(with:completionHandler:)](networkextension/nepackettunnelprovider/stoptunnel(with:completionhandler:).md)
