Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Use Try::Tiny in docs that reference removed catch sub #18

Merged
merged 1 commit into from

2 participants

@rwstauner

Reading the docs (the Rollback Exceptions section) I saw a section that passed two subs,
the second appearing to be an error handler.

I was confused until I read in the change log that there used to be a 'catch' block,
so I'm assuming this pod was leftover from that change.

I wrapped the subs in a try/catch (using Try::Tiny).

If this is not correct, please review the docs to clarify.
Thanks!

@theory theory merged commit 668007a into from
@theory
Owner

Merged, thanks for the catch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 14, 2012
  1. @rwstauner
This page is out of date. Refresh to see the latest.
Showing with 25 additions and 19 deletions.
  1. +25 −19 lib/DBIx/Connector.pm
View
44 lib/DBIx/Connector.pm
@@ -541,15 +541,18 @@ The rollback error.
For example:
+ use Try::Tiny;
$conn->txn(sub {
- # ...
- }, sub {
- if (eval { $_->isa('DBIx::Connector::RollbackError') }) {
- say STDERR 'Transaction aborted: ', $_->error;
- say STDERR 'Rollback failed too: ', $_->rollback_error;
- } else {
- warn "Caught exception: $_";
- }
+ try {
+ # ...
+ } catch {
+ if (eval { $_->isa('DBIx::Connector::RollbackError') }) {
+ say STDERR 'Transaction aborted: ', $_->error;
+ say STDERR 'Rollback failed too: ', $_->rollback_error;
+ } else {
+ warn "Caught exception: $_";
+ }
+ };
});
If a L<C<svp()>|/"svp"> rollback fails and its surrounding L<C<txn()>|/"txn">
@@ -557,20 +560,23 @@ rollback I<also> fails, the thrown DBIx::Connetor::TxnRollbackError exception
object will have the the savepoint rollback exception, which will be an
DBIx::Connetor::SvpRollbackError exception object in its C<error> attribute:
+ use Try::Tiny;
$conn->txn(sub {
- $conn->svp(sub { # ... });
- }, sub {
- if (eval { $_->isa('DBIx::Connector::RollbackError') }) {
- if (eval { $_->error->isa('DBIx::Connector::SvpRollbackError') }) {
- say STDERR 'Savepoint aborted: ', $_->error->error;
- say STDERR 'Its rollback failed too: ', $_->error->rollback_error;
+ try {
+ $conn->svp(sub { # ... });
+ } catch {
+ if (eval { $_->isa('DBIx::Connector::RollbackError') }) {
+ if (eval { $_->error->isa('DBIx::Connector::SvpRollbackError') }) {
+ say STDERR 'Savepoint aborted: ', $_->error->error;
+ say STDERR 'Its rollback failed too: ', $_->error->rollback_error;
+ } else {
+ say STDERR 'Transaction aborted: ', $_->error;
+ }
+ say STDERR 'Transaction rollback failed too: ', $_->rollback_error;
} else {
- say STDERR 'Transaction aborted: ', $_->error;
+ warn "Caught exception: $_";
}
- say STDERR 'Transaction rollback failed too: ', $_->rollback_error;
- } else {
- warn "Caught exception: $_";
- }
+ };
});
But most of the time, you should be fine with the stringified form of the
Something went wrong with that request. Please try again.