# perldoc > Specio::Exception

---
type: CommandReference
command: Specio::Exception
mode: perldoc
section: 
source: perldoc
---

## Quick Reference

- `$exception->message` — get error message
- `$exception->type` — get type constraint object
- `$exception->value` — get value that failed
- `$exception->as_string` — get exception as string with stack trace
- `$exception->stack_trace` — get Devel::StackTrace object
- `$_->isa('Specio::Exception')` — check if exception is of this class
- `catch { ... }` with Try::Tiny to handle failures

## Name

Specio::Exception — An exception class for type constraint failures

## Synopsis

perl
use Try::Tiny;

try {
    $type->validate_or_die($value);
}
catch {
    if ( $_->isa('Specio::Exception') ) {
        print $_->message, "\n";
        print $_->type->name, "\n";
        print $_->value, "\n";
    }
};
## Description

This exception class is thrown by Specio when a type check fails. It emulates the Throwable::Error API, but doesn't use that module to avoid adding a dependency on Moo.

## Options

- `$exception->message` — The error message associated with the exception.
- `$exception->stack_trace` — A Devel::StackTrace object for the exception.
- `$exception->type` — The type constraint object against which the value failed.
- `$exception->value` — The value that failed the type check.
- `$exception->as_string` — The exception as a string, including the message and stack trace.
- Stringification is overloaded to call `as_string`.

## Examples

The synopsis above demonstrates the typical use case: catching a Specio::Exception and extracting the message, type, and value.

## See Also

- [Specio](http://localhost/phpMan.php/perldoc/Specio/markdown) — the type constraint system
- [Throwable::Error](http://localhost/phpMan.php/perldoc/Throwable%3A%3AError/markdown) — the API this class emulates
- [Devel::StackTrace](http://localhost/phpMan.php/perldoc/Devel%3A%3AStackTrace/markdown) — used for stack traces
- [Try::Tiny](http://localhost/phpMan.php/perldoc/Try%3A%3ATiny/markdown) — recommended for try/catch
- [Source code repository](https://github.com/houseabsolute/Specio)