# CKEditorError

class

The CKEditor error class.

You should throw `CKEditorError` when:

* An unexpected situation occurred and the editor (most probably) will not work properly. Such exception will be reported to the callbacks registered with [`onEditorError()`](module_core_errorreporter.md#function-onEditorError),
* If the editor is incorrectly integrated or the editor API is used in the wrong way. This way you will give feedback to the developer as soon as possible. Keep in mind that for common integration issues which should not stop editor initialization (like missing upload adapter, wrong name of a toolbar component) we use [`logWarning()`](module_utils_ckeditorerror.md#function-logWarning) and [`logError()`](module_utils_ckeditorerror.md#function-logError) to improve developers experience and let them see the a working editor as soon as possible.

```typescript
/**
 * Error thrown when a plugin cannot be loaded due to JavaScript errors, lack of plugins with a given name, etc.
 *
 * @error plugin-load
 * @param pluginName The name of the plugin that could not be loaded.
 * @param moduleName The name of the module which tried to load this plugin.
 */
throw new CKEditorError( 'plugin-load', {
	pluginName: 'foo',
	moduleName: 'bar'
} );
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/ckeditorerror.ts#L43)

<a id="properties">

## Properties

<a id="member-context">

### `context: object | null | undefined` _(readonly)_

A context of the error by which error reporting works out which editor the error came from.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/ckeditorerror.ts#L47)

<a id="member-data">

### `data?: object` _(readonly)_

The additional error data passed to the constructor. Undefined if none was passed.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/ckeditorerror.ts#L52)

<a id="methods">

## Methods

<a id="function-constructor">

### `constructor( errorName, context?, data?, originalError? )`

Creates an instance of the CKEditorError class.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/ckeditorerror.ts#L67)

#### Parameters

* `errorName: string`

  The error id in an `error-name` format. A link to this error documentation page will be added to the thrown error's `message`.

* `context?: object | null`

  A context of the error by which [error reporting](module_core_errorreporter.md#function-onEditorError) works out which editor the error came from. Pass the editor, the context, or the plugin or command that throws the error. Pass `null` if the error should not be attributed to any editor (e.g. during the editor initialization).

* `data?: object`

  Additional data describing the error. A stringified version of this object will be appended to the error message, so the data are quickly visible in the console. The original data object will also be later available under the [`data`](#member-data) property.

* `originalError?: Error`

  An optional original error that is being wrapped in the `CKEditorError` instance.

<a id="function-is">

### `is( type ) → boolean`

Checks if the error is of the `CKEditorError` type.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/ckeditorerror.ts#L85)

#### Parameters

* `type: string`

#### Returns

* `boolean`

#### Static methods

<a id="static-function-rethrowUnexpectedError">

### `rethrowUnexpectedError( error, context ) → never` _(static)_

A utility that ensures that the thrown error is a [`CKEditorError`](module_utils_ckeditorerror-CKEditorError.md) one. Only a [`CKEditorError`](module_utils_ckeditorerror-CKEditorError.md) is reported to the callbacks registered with [`onEditorError()`](module_core_errorreporter.md#function-onEditorError), so wrapping an unexpected error in one is what makes it reach them.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/ckeditorerror.ts#L99)

#### Parameters

* `error: Error`

  The error to rethrow.

* `context: object`

  An object connected through properties with the editor instance. This context is what error reporting uses to work out which editor the error came from.

#### Returns

* `never`

---

Full index of the CKEditor 5 API reference: [llms.txt](llms.txt)
