Results 1 to 5 of 5

Thread: Spring Async UncaughtExceptionHandler

  1. #1
    Join Date
    Jan 2012
    Posts
    9

    Default Spring Async UncaughtExceptionHandler

    Code:
    @Async
    public void asyncExceptionTest() {
        int i=1/0;
    }
    How can I log this using Spring Async framework without having to put try catch around every async method? It doesnt seem to pass to the DefaultUncaughtExceptionHandler like normal.

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

    Default

    Hello


    Consider use AOP (around advice)

    Let me know your advance
    - 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
    Jan 2012
    Posts
    9

    Default

    Thanks for your reply...AOP seems like a solution but I think it would be better if you could directly specify the error handler. Would be more elegant IMO.

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

    Default

    AOP offer a special type of advice. After advice, it is executed if an exception was thrown or not, even
    you can work with specific types of exceptions like parameters, read documentation for more details.

    To be honest I think AOP is the best option
    - 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

  5. #5
    Join Date
    Jan 2012
    Posts
    9

    Default

    Thanks for your response but I think using AOP is a bit heavyweight and it would be much clearer, transparent and explicit if you could define your own ErrorHandler. There is something available for the @Scheduled to allow you to specify the error handler not sure why not for the @Async?

Posting Permissions

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