GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Data::Object::Role::Errable(3) User Contributed Perl Documentation Data::Object::Role::Errable(3)

Data::Object::Role::Errable

Errable Role for Perl 5

  package Example;

  use Moo;

  with 'Data::Object::Role::Errable';

  package main;

  my $example = Example->new;

  # $example->error('Oops!')

This package provides a mechanism for handling errors (exceptions). It's a more structured approach to being "throwable". The idea is that any object that consumes this role can set an error which automatically throws an exception which if trapped includes the state (object as thrown) in the exception context.

This package integrates behaviors from:

Data::Object::Role::Tryable

This package uses type constraints from:

Data::Object::Types

This package has the following attributes:

  error(ExceptionObject)

This attribute is read-write, accepts "(ExceptionObject)" values, and is optional.

This package implements the following methods:

  error(ExceptionObject $exception | HashRef $options | Str $message) : ExceptionObject

The error method takes an error message (string) or hashref of exception object constructor attributes and throws an "exception". If the exception is trapped the exception object will contain the object as the exception context. The original object will also have the exception set as the error attribute. The error attribute can be cleared using the "error_reset" method.

error example #1
  package main;

  my $example = Example->new;

  $example->error('Oops!');

  # throws exception
    
error example #2
  package main;

  my $example = Example->new;

  $example->error({ message => 'Oops!'});

  # throws exception
    
error example #3
  package main;

  my $example = Example->new;
  my $exception = Data::Object::Exception->new('Oops!');

  $example->error($exception);

  # throws exception
    

  error_reset() : Any

The error_reset method clears any exception object set on the object.

error_reset example #1
  package main;

  my $example = Example->new;

  eval { $example->error('Oops!') };

  $example->error_reset
    

Al Newkirk, "awncorp@cpan.org"

Copyright (C) 2011-2019, Al Newkirk, et al.

This is free software; you can redistribute it and/or modify it under the terms of the The Apache License, Version 2.0, as elucidated in the "license file" <https://github.com/iamalnewkirk/data-object-role-errable/blob/master/LICENSE>.

Wiki <https://github.com/iamalnewkirk/data-object-role-errable/wiki>

Project <https://github.com/iamalnewkirk/data-object-role-errable>

Initiatives <https://github.com/iamalnewkirk/data-object-role-errable/projects>

Milestones <https://github.com/iamalnewkirk/data-object-role-errable/milestones>

Contributing <https://github.com/iamalnewkirk/data-object-role-errable/blob/master/CONTRIBUTE.md>

Issues <https://github.com/iamalnewkirk/data-object-role-errable/issues>

2020-04-15 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.