# yatra/trunk/app/Exceptions/ValidationException.php

Yatra – Travel Booking &amp; Tour Operator Software, version trunk. 61 lines.

- Page: https://pluginprobe.com/plugins/yatra/trunk/code/app/Exceptions/ValidationException.php
- Raw: https://pluginprobe.com/plugins/yatra/trunk/raw/app/Exceptions/ValidationException.php
- Modified: 2026-04-14T03:47:24+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/yatra/trunk/code/app/Exceptions/ValidationException.php#L10-L20`.

```php
<?php

declare(strict_types=1);

namespace Yatra\Exceptions;

/**
 * Validation Exception
 * 
 * Thrown when input validation fails
 */
class ValidationException extends YatraException
{
    protected string $errorCode = 'validation_error';

    /**
     * @var array Validation errors by field
     */
    protected array $errors = [];

    public function __construct(string $message = 'Validation failed', array $errors = [], int $code = 400, ?\Exception $previous = null)
    {
        $this->errors = $errors;
        parent::__construct($message, $code, $previous, ['validation_errors' => $errors]);
    }

    /**
     * Get validation errors
     */
    public function getErrors(): array
    {
        return $this->errors;
    }

    /**
     * Add validation error for a field
     */
    public function addError(string $field, string $message): self
    {
        $this->errors[$field][] = $message;
        $this->context['validation_errors'] = $this->errors;
        return $this;
    }

    /**
     * Check if field has errors
     */
    public function hasError(string $field): bool
    {
        return isset($this->errors[$field]) && !empty($this->errors[$field]);
    }

    /**
     * Get errors for specific field
     */
    public function getFieldErrors(string $field): array
    {
        return $this->errors[$field] ?? [];
    }
}

```
