• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do i know if a method was executed without exceptions  RSS feed

 
Jhon Parker
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i recently decided to stop creating my crud methods like inserts and delete methods return booleans like true or false since i read in some article that it was a old practice and the new way was handling exceptions , So i started to making them like voids this methods have a try and catch inside of them so they don't throw exceptions out where they are invoked, my question is if i'm invoking them in a controller class how do i know if they where executed without problems.

here is where i'm invoking them.



if the new way of doing things is without returning a value in crud delete and insert methods how can i set my json answer to true or false if i don't know i the delete methos was executed without problems
 
Arun Kumarr
Ranch Hand
Posts: 662
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your, "roleDAO.eliminarRolPorId(...)" method has a try and catch which is handling any exceptions, the you cannot set your jsonAnswer to anything.
Plainly put, there is no information carried from the DAO method to the calling method, so there is no way to confirm if it was successful or failed.

Secondly, I think you have misunderstood "management by exception". Basically you are expecting your dao layer to throw exception if failed and if there is no exception, then it simply means it was successful.
This poses one question for you to think. You are now relying on the underlying framework to "always" throw an exception, if it cannot successfully perform an operation.
Say, you have fired a query to the database to delete a record and it was executed and there was no exceptions thrown, but when you go to the database, you still see that record. Possible because you have not committed the transaction you opened or your operation merely participated in a transaction opened elsewhere and it was not committed or something else other than your operation failed.
Is it reliable??
 
Arun Kumarr
Ranch Hand
Posts: 662
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...since i read in some article that it was a old practice and the new way was handling exceptions ,...


- Can you share that article?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!