[Dbix-class] Throwing exceptions from exception_action
Hi DBIC gurus! I tried to throw typed exceptions from exception_action based on DBD error codes. And to no avail. Here are problems that I've faced: 1. There are very little docs and few tests on exception_action. 2. exception_action is being called twice ( at least more than once ) for every RDBMS error. This is demonstrated here http://paste.scsys.co.uk/194724 Note that $DBI::state and $DBI::err are set only the first time call 3. $DBI::state and $DBI::err are not always set to actual RDBMS error codes during exception_action call. $DBI::err is set to default 20 in the following case with populate for instance: http://paste.scsys.co.uk/194725 BTW, I've noticed strange warning for the case when exception_action is in use and populate() call initiates DB error: A DBIx::Class::Storage::TxnScopeGuard went out of scope without explicit commit or error. Rolling back. at ... What I basically want to do is: MySchema-execption_action( sub { my $e = shift; if ( is_canstraint_fail() ) { UniqueConstraintFail-throw( $e ); } else { GeneralException-throw( $e ); } }); And later: eval { $schema-resultset( 'user' )-create({ user fileds go here }); }; if ( UniqueConstraintFail-caught ) { UserExists-throw } elsif What are your suggestions to solve this? What are bugs and what are not? ___ List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class IRC: irc.perl.org#dbix-class SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/ Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
Re: [Dbix-class] Throwing exceptions from exception_action
On Mon, Apr 23 2012, Konstantin A. Pustovalov la...@adriver.ru wrote: I tried to throw typed exceptions from exception_action based on DBD error codes. And to no avail. hi Konstantin, I can't comment on your DBIx::Class problem, but if you want to use typed exceptions, I'd recommend using Trycatch to handle them: https://metacpan.org/module/TryCatch this is a nice implementation of java-style exception semantics in perl. HTH patrick -- Patrick Meidl +43 1 9688226 (home) Pazmanitengasse 4/10 . +43 680 2072780 (mobile) 1020 Wien patr...@pantheon.at Austria .. http://pmeidl.homelinux.net/ -- ___ List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class IRC: irc.perl.org#dbix-class SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/ Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk