PHPackages                             carono/yii2-validation-exception - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. carono/yii2-validation-exception

ActiveYii2-extension[Validation &amp; Sanitization](/categories/validation)

carono/yii2-validation-exception
================================

An exception for the model in case of erroneous validation

1.0.0(9mo ago)07MITPHPPHP ^7.4 || 8.\*

Since Jul 31Pushed 5mo agoCompare

[ Source](https://github.com/carono/yii2-validation-exception)[ Packagist](https://packagist.org/packages/carono/yii2-validation-exception)[ RSS](/packages/carono-yii2-validation-exception/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

Yii2 Validation Exception
=========================

[](#yii2-validation-exception)

[![License](https://camo.githubusercontent.com/cfdea844e4ddd1deb5e7f5f4a272f6014645503e751cfcc72e05bed5b44abeac/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6361726f6e6f2f796969322d76616c69646174696f6e2d657863657074696f6e)](https://github.com/carono/yii2-validation-exception/blob/master/LICENSE)[![PHP Version](https://camo.githubusercontent.com/1291c55c60d5b87ccd095a17016060f52bc84c1e2d8306ea1a76f7c7ba4b658f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6361726f6e6f2f796969322d76616c69646174696f6e2d657863657074696f6e)](https://packagist.org/packages/carono/yii2-validation-exception)

A simple Yii2 extension that provides a specialized exception class for handling model validation errors.

Features
--------

[](#features)

- Throws an exception with the first validation error message when model validation fails
- Provides direct access to the failed model instance
- Easy integration with Yii2 applications

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require carono/yii2-validation-exception

```

or add

```
"carono/yii2-validation-exception": "*"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

```
use carono\yii2\exceptions\ValidationException;
use yii\base\Model;

$model = new Model();
$model->addError('attribute', 'Validation error message');

// Throw exception with the first validation error
throw new ValidationException($model);

// Or use it in a try-catch block
try {
    if (!$model->validate()) {
        throw new ValidationException($model);
    }
    // Continue with valid model
} catch (ValidationException $e) {
    // Access the error message
    echo $e->getMessage(); // "Validation error message"

    // Access the model instance
    $failedModel = $e->model;
}
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Author
------

[](#author)

Alexander Kasyanov - [carono.ru](https://carono.ru) -

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance64

Regular maintenance activity

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

284d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6193985?v=4)[Александр Касьянов](/maintainers/carono)[@carono](https://github.com/carono)

---

Top Contributors

[![carono](https://avatars.githubusercontent.com/u/6193985?v=4)](https://github.com/carono "carono (1 commits)")

---

Tags

yii2extension

### Embed Badge

![Health badge](/badges/carono-yii2-validation-exception/health.svg)

```
[![Health](https://phpackages.com/badges/carono-yii2-validation-exception/health.svg)](https://phpackages.com/packages/carono-yii2-validation-exception)
```

###  Alternatives

[kdn/yii2-domain-validator

Domain name validator for Yii 2.

11122.3k1](/packages/kdn-yii2-domain-validator)[nepstor/yii2-datetime-compare-validator

Yii2 validator for compare datetime.

1283.7k1](/packages/nepstor-yii2-datetime-compare-validator)[bryglen/yii2-validators

credit card validation yii 2

1426.7k](/packages/bryglen-yii2-validators)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
