Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
  • salvin francis
  • Frits Walraven
  • Piet Souris

Should I use IndexOf List in this case?

Ranch Hand
Posts: 717
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:That last bit of your code (the bit where you are trying to find the pet and whether it is sold) should be a call to the method Carey showed.

Of course that new method ought to be in a service layer rather than in the controller, but small steps...

Hi Dave,

Someone just told me that I should check if the order is null before I do the checking on the petId,

So, is it ok if I just add a && condition to state petId is null and with the above, then I throw a ResponseStatusException?

I have also refactored the code to use a Service layer but my brain is not working cos when I started with this base line to check if the order is null, then I do not know what to return ?

Could you advise me ? tks.
Saloon Keeper
Posts: 7616
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When faced with this kind of  decision, one where throwing an Exception is a possible choice, think to yourself, "is this an exceptional state?"  That is, during any sort of normal running of the program could this ever occur unless there's a programming bug, a hicup in some dependent service, or perhaps, bad user input that wasn't dealt with properly? Could this state be dealt with right here and now in this method or do we need to shrug our shoulders and pass the error back up the calling chain to be dealt with? Should execution continue on or is the state such that continuing would cause further problems?

If you look at your null Order problem against these questions it should be somewhat obvious as to your course of action.
    Bookmark Topic Watch Topic
  • New Topic