Results 1 to 6 of 6

Thread: Spring Exception Handling

  1. #1
    Join Date
    Nov 2006
    Posts
    12

    Default Spring Exception Handling

    Hi all ,

    I ahve the following requirement. I need to be able to configure an exception and if the particular exception is caught I need the handler to be invoked.

    Is this possible in Spring

    -Thanks,

  2. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,791

    Default

    you can create your own set of Exceptions and throw them
    and handle in some Action/Controller

    something like this

    Code:
    public List<Proveedor> getAllProveedoresDAO()throws MyGlobalException{
    	List<Proveedor> mylist = new ArrayList<Proveedor>();
    	try{
    		mylist = (List) getHibernateTemplate().find("FROM Proveedor p WHERE p.idProveedor!='100000' ");			
    		if(mylist.isEmpty())
    			throw new MyListEmptyException();
    	}
    	catch(DataAccessException dae){
    		logger.info("DataAccessException"+dae.getMessage());
    		throw new MyGlobalException();
    	}	
    	return mylist;
    }
    am i right?

    regards
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  3. #3
    Join Date
    Nov 2006
    Location
    Germany
    Posts
    452

    Default

    Hi,

    if you just want to caught an exception, you can wrap the call with an after-throwing advice.

    Have a look here if you want to go for Spring XML-AOP

    regards
    agim

  4. #4
    Join Date
    Nov 2006
    Posts
    12

    Default

    Thanks for ur reply. Can I achieve the same using Spring IOC instead of AOP?

  5. #5
    Join Date
    Nov 2006
    Location
    Germany
    Posts
    452

    Default

    Hello,

    yes it is possible by using a proxyfactory bean with an afterthrwoing advice.
    Have a look here , after that you have to implement the afterthrowingadvice interface.

    Here is the documentation about that

    Best regards
    agim

  6. #6
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Quote Originally Posted by sreepriyar View Post
    Can I achieve the same using Spring IOC instead of AOP?
    I'm not entirely sure I understand the question.
    Last edited by karldmoore; Aug 29th, 2007 at 11:54 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •