---
name: "SQL::Translator::Role::Error"
section: "3pm"
platform: "linux"
package: "libsql-translator-perl"
version: "1.66-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/SQL::Translator::Role::Error"
---

# SQL::Translator::Role::Error(3pm)

Error setter/getter for objects and classes

## NAME

SQL::Translator::Role::Error - Error setter/getter for objects and classes

## SYNOPSIS

In the class consuming the role:

```
    package Foo;
    use Moo;
    with qw(SQL::Translator::Role::Error);
    sub foo {
        ...
        return $self->error("Something failed")
            unless $some_condition;
        ...
    }
```

In code using the class:

```
    Foo->foo or die Foo->error;
    # or
    $foo->foo or die $foo->error;
```

## DESCRIPTION

This Moo::Role provides a method for getting and setting error on a class or object.

## METHODS

### $object\_or\_class-\>error(\[$message\])

If called with an argument, sets the error message and returns undef, otherwise returns the message.

As an implementation detail, for compatibility with Class::Base, the message is stored in `"$object->{_ERROR}"` or `$Class::ERROR`, depending on whether the invocant is an object.

## SEE ALSO

- •

  "Error Handling" in Class::Base
