Catching DataAccessExceptions with AOP

I have a webapp using Spring + Hibernate through JPA, Spring is effectively translating all persitence exceptions into variations of DataAccessException.

I am now trying to catch these DataAccessExceptions in an AOP pointcut like this:

@Aspect public class AspectException { @AfterThrowing(pointcut = "within(com.mypackage.dao..*)", throwing = "error") public void catchException(Throwable error) { MyOwnException e = new MyOwnException("ERROR!", error); throw e; } }

Now this aspect works if in my DAO I throw a custom exception, but won't work with Spring's DataAccessExceptions!

Any idea why this is happenning?

-------------Problems Reply------------

Have you throught about exception translation?

http://docs.spring.io/spring/docs/current/spring-framework-reference/html/jdbc.html#jdbc-SQLExceptionTranslator

Category:java Views:2 Time:2017-09-11

Related post

  • ExpectedException not catching exception, but I can catch it with try catch 2009-03-12

    Any ideas on this one? I'm trying to write a unit test that will delete an item and confirm that item is no longer in a repository by trying to retrieve the item by its ID which should throw a DataAccessException. However, the test keeps failing. I a

  • How does compilation work with AOP? 2010-06-05

    I need quick answer to a simple thing in AOP. If i have a code deployed at client side and i have written new aspects, which i want in the client side software. do i have to "recompile" complete software with "original" code and new "AOP" code? (with

  • catch value with jQuery 2010-08-17

    how get values from input? I have this script, but i don't now, how catch values with jquery <script type="text/javascript"> $(document).ready(function() { $("#fileInput2").uploadify({ //How get value from input (fileInput2) }); }); </script

  • Throwing an exception in a catch block with hibernate before close in finally 2010-12-30

    So, I want some confirmation on this. I will explain in pseudo code. public void myFunc() throws Exception{ Session session = Hibernate.getSession(); try{ //do somthing } catch(Exception ex){ throw ex; } finally{ session.close(); } } Therefore, if a

  • How to catch event with hardware back button on android? 2011-11-11

    How to catch event with hardware back button on android ? I need to supress user to go back and I when click on back button on phone to show message and not to go on previous activity. How to do that ? --------------Solutions------------- you can do

  • videos stall and wait for feed to catch up with explorer 9, no problem with 8 2013-05-17

    videos stall and wait for feed to catch up with explorer 9, no problem with 8 --------------Solutions------------- Hi RONWESTRICH, I would suggest you to try updating the flash installed on your computer for the Internet Explorer browser and check if

  • sometimes on movies the picture freezes & sound skips till it catches up with the picture, & sound stops when on u tube after a a few minutes. 2013-01-02

    sometimes on movies the picture freezes & sound skips till it catches up with the picture, & sound stops when on u tube after a a few minutes. --------------Solutions------------- Hi, Does this happen with any particular video file or every f

  • Media player won't skip forward, the picture freezes while the sound continues. sometimes the picture will catch up with the sound, most times not. How do I fix that? 2014-03-08

    After launching a video in Windows Media Player, I tried to skip forward or backward using the 'play line or progress line' at the bottom of the viewing area. The sound will either go forward or backward, but the picture freezes. Most times the pictu

  • Can we simplify programmatic transaction management with AOP? 2011-11-30

    I wanted to set the transactionManager based on some input criteria and hence I moved from declarative to programmatic transaction management . something like public User saveUser(NewUser newUser){ return transactionTemplate.execute(new TransactionCa

  • Generating Spring DataAccessExceptions with legacy frameworks 2012-01-06

    I'm currently rewriting a legacy web application where the backend is using, amongst other things CORBA and another RPC framework - both are quite old and do not have Spring support. My hope is that I can eventually write a @Repository classes to han

  • Issue with AOP and JMX without Spring 2014-06-03

    I wrote an program to trace the performance of an application using AspectJ with a requirement that the tracing can be enabled or disabled at runtime using JMX so that i can change the value using jconsole/HtmlAdaptorServer. Now again i have to keep

  • Catching exceptions with tomcat and a servlet 2008-10-09

    I have set-up tomcat to catch all my exceptions and pass them to a servlet with the following in web.xml. <servlet-mapping> <servlet-name>exception</servlet-name> <url-pattern>/exception</url-pattern> </servlet-mappin

  • try-catch blocks with the return type 2009-03-02

    If I have a method that returns something, like public DataTable ReturnSomething() { try { //logic here return ds.Tables[0]; } catch (Exception e) { ErrorString=e.Message; } } This produces compiler error, obviously because catch{} block does not ret

  • Why does resharper say 'Catch clause with single 'throw' statement is redundant'? 2009-06-19

    I thought throwing an exception is good practice to let it bubble back up to the UI or somewhere where you log the exception and notify the user about it. Why does resharper say it is redundant? try { File.Open("FileNotFound.txt", FileMode.Open); } c

  • Catching errors with both mod_cgi & mod_perl 2009-07-23

    Thanks to everyone in advance. I've been doing some research on error handling and I don't feel like I'm getting a solid understanding of what I should do. Preamble: My code is living in Apache and executed in the browser, my goals don't include comm

  • What is the difference between SET xact_abort ON and try/catch block with Transaction handling in sqlserver 2005? 2009-08-11

    I need to improve some existing stored procedures in my project for better transaction handling. I understand I can use the SET XACT_Abort ON statement in my procedure so that transaction will be automatically rolled back in case of errors. I can als

  • Catching event with stopped propagation 2009-10-08

    Is it possible to somehow catch event, if it's propagation was stopped? $('span').click(function(e) { e.stopPropagation(); }); Maybe there are some kind of global handler? Like: Event.registerHandler('click', function(e) { alert('thanks'); }); There

  • Merge catch blocks with exactly the same code? 2009-12-12

    This question already has an answer here: Catch multiple Exceptions at once? 17 answers I want to merge the catch blocks in the following code for code reuse reasons: try { DoSomeInputOutput(); } catch (InvalidOperationException ex) { HandleKnownExce

  • problem in Spring session scope bean with AOP 2009-12-23

    I want to inject currentUser instance in HomeController class. so for every request, HomeController will have currentUser object. My configuration: <bean id="homeController" class="com.xxxxx.actions.HomeController"> <property name="serviceEx

  • C# question - how to populate a catch statement with the specific possible exceptions from the code in the try? 2010-01-29

    I'm using VS2008 and have ReSharper too. My question is how can I automate the creation of a try/catch block for which the catch is specifically populated with the possible exception from the try block? (i.e. not just put in an Exception ex) Backgrou

  • Catch keypress with android 2010-02-14

    How can i catch a phone keypress with the android SDK? i've been looking around for hours without finding anything.. For example: In some cases, i want to catch the message when a user presses the "hang up" button on the phone, and then discard the m

  • Use case for try-catch-finally with both catch and finally 2010-02-17

    I understand how try-catch works and how try-finally works, but I find myself using those (usually) in two completely different scenarios: try-finally (or using in C# and VB) is mostly used around some medium-sized code block that uses some resource

  • Help catching AV with WinDbg and ADPlus 7.0 2010-06-07

    I want to catch Memory Access Violation in SQL Server Compact Edition like this described at http://debuggingblog.com/wp/2009/02/18/memory-access-violation-in-sql-server-compact-editionce/ The suggested config is: <ADPlus> <Settings> <

  • Catching exceptions with BeginRead in C# 2010-07-24

    When using asynchronous code to read from streams etc using the BeginXXX / EndXXX pattern, I believe that any exceptions that occur during the process will be thrown when the call to EndXXX is made. Does this mean that the initial call to BeginXXX wi

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.160 (s). 11 q(s)