# UnknownCommandException

> UnknownCommandException represents an exception caused by incorrect usage of a console command.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [console](/docs/api/yii/console/index.md) › UnknownCommandException

| class | `yii\console\UnknownCommandException` |
| --- | --- |
| Extends | [`Exception`](/docs/api/yii/console/exception/index.md) » [`yii\base\UserException`](/docs/api/yii/base/userexception/index.md) » [`yii\base\Exception`](/docs/api/yii/base/exception/index.md) » [`Exception`](https://www.php.net/manual/en/class.exception.php) |
| Since | 2.0.11 |
| Source | [`framework/console/UnknownCommandException.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/console/UnknownCommandException.php#L19) |

UnknownCommandException represents an exception caused by incorrect usage of a console command.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-command"></span>`$command` | `string` | The name of the command that could not be recognized. Default: `null`. | `UnknownCommandException` |
| <span id="property-application"></span>`$application` protected | [`Application`](/docs/api/yii/console/application/index.md) | Default: `null`. | `UnknownCommandException` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Construct the exception. | `UnknownCommandException` |
| [`getName()`](#method-getName) |  | `UnknownCommandException` |
| [`getSuggestedAlternatives()`](#method-getSuggestedAlternatives) | Suggest alternative commands for [`$command`](/docs/api/yii/console/unknowncommandexception/index.md#property-command) based on string similarity. | `UnknownCommandException` |

## Method details

### __construct() <span id="method-__construct"></span>

```php
public function __construct(string $route, yii\console\Application $application, int $code = 0, Throwable|null $previous = null)
```

Construct the exception.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$route` | `string` | The route of the command that could not be found. |
| `$application` | [`Application`](/docs/api/yii/console/application/index.md) | The console application instance involved. |
| `$code` | `int` | The Exception code. |
| `$previous` | [`Throwable`](https://www.php.net/manual/en/class.throwable.php)`\|null` | The previous exception used for the exception chaining. |

### getName() <span id="method-getName"></span>

```php
public function getName(): string
```

**Returns**

`string`: The user-friendly name of this exception

### getSuggestedAlternatives() <span id="method-getSuggestedAlternatives"></span>

```php
public function getSuggestedAlternatives(): array
```

Suggest alternative commands for [`$command`](/docs/api/yii/console/unknowncommandexception/index.md#property-command) based on string similarity.

Alternatives are searched using the following steps:

- suggest alternatives that begin with `$command`
- find typos by calculating the Levenshtein distance between the unknown command and all
  available commands. The Levenshtein distance is defined as the minimal number of
  characters you have to replace, insert or delete to transform str1 into str2.

**Returns**

`array`: A list of suggested alternatives sorted by similarity.

**See also**

- <https://www.php.net/manual/en/function.levenshtein.php>