• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception Handling  RSS feed

 
Gautamaxa roy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am in Portlet development where i need to handle exception handling.Brief about my requiremnt is below.
Initially, we were interacting with Corner Stone Service and displaying information in Portlet.
Now, we are gradulally migarting Corner Stone users to SILVA. So, we need to integrate with SILVA and Corner Stone also.

I need to handle following exeception in try -catch
1> CornerStone is down but SILVA is UP
2> CornerStone is up but SILVA is down
3> CornerStone and SILVA both are up and running
4> CornerStone and SILVA both are down


It can be assumed that SILVA application would throw the same exception as CornerStone is throwing as per the existing code.
Now, i need to design so that above said bold exception are handled properly when both CornerStone and SILVA are in place.
My existing code only with CornerStone application is below.



Now changed code including both CornerStone and SILVA service. There is no change in CornerStone class.
I changed only in RestRequest class. Only the following snippet is added in RestRequest class.


Could you help me redesign the above code so that both the applications are wprking fine ?

Regards
Gautam
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Your code was illegible because the lines were too long and there were embedded bold tags. I think I have sorted it out.
Please write down simply what you plan to do for those four conditions. One of the four you mention would appear to be normal, so no Exception is expected. In the other three, if a distant service is down, what are you going to do? Phone the people at the other end? If so, isn't the only available response to turn the computer off and try again later?

Don't write throws Exception; write something more specific.
 
Gautamaxa roy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ritchie,

thanks a lot for your response.
My requirements in brief is below.

There are three exception with my existing code (CsticketsummaryPortlet.java class ).
In fact, these three exceptions were enough when there is only CornerStone Service in place.
and to handle
1> When Corner Stone application is up
2> When Corner Stone application is down



These exceptions were for CornerStone service.
Now, i need these same execption work for both CornerStone and SILVA service.
What would be the best way to deal with ?
Could you advise?
regards
Gautam

 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to work that out. You know your application. I don't. A few suggestions:-
  • Can you add to that enum of constants?
  • Can you create more exception subclasses?
  • How do you tell if both services are down? Or does the first exception take you directly to the catch?
  • Why are you handling plain simple Exception?
  •  
    Gautamaxa roy
    Greenhorn
    Posts: 5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Ritchie,

    Thanks again for your advice. Actually,CornerStone and Silva both are webservices and my application is interacting with both.
    My understanding is that when any of these applications is down, my application suppose to face
    java.net.ConnectException exception.


    One of the requirements is that i have to call first CornerStone service and then Silva service.
    Say, the CornerStone service is down and at that point it would throw java.net.ConnectException exception.
    Inspite of that, we need to call SILVA service expecting it would be up and running.


    Could you suggest any wayout?

    regards
    Gautam
     
    Winston Gutkowski
    Bartender
    Posts: 10575
    66
    Eclipse IDE Hibernate Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Gautamaxa roy wrote: One of the requirements is that i have to call first CornerStone service and then Silva service.
    Say, [b]the CornerStone service is down and at that point it would throw java.net.ConnectException exception.
    Inspite of that, we need to call SILVA service expecting it would be up and running.

    Could you suggest any wayout?

    Sure: and then use those boolean variables to do what you want.

    However, it's very simplistic (and possibly wrong) because we really have no idea what you're doing. All we can see is a lot of very hard-to-read code.

    My advice:
    1. Write out IN ENGLISH (or your native language) what the code currently does.
    2. Write out what you want it to do.
    3. Highlight the differences for us.

    Then we should be able to help you better.

    I'd also re-read Campbell's post because what he said (especially about Enums) is pretty much what I would have. In fact I think I might start out with: and work from there.

    HIH

    Winston
     
    Gautamaxa roy
    Greenhorn
    Posts: 5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Winston,

    Thanks a lot for your response. But i have a different thought. Code snippet is below.




    My project requirements
    1> To call CorenerStone service followed by SILVA service.
    2> Both CornerStone and SILVA service are assumed to kick off same kind of exceptions
    3> Based on the exceptions, we need to display values in JSP file.

    Could you advise me the pros and cons of the above approach?

    regards
    Gautam
     
    Campbell Ritchie
    Marshal
    Posts: 56536
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Don't go returning anything from a finally. Nor throw Exceptions from there. The reason is that the finally will override whatever happens in the rest of the method. Daft and silly example:-Now, if that isn't badly‑designed code, I don't know what is. I challenge you to find the argument i for which it will return 123 and the argument j for which it will return -999.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!