teleivo
(Ivo Ulrich)
July 29, 2016, 8:10am
1
Hello
can someone please tell me why
OrderService.discontinueOrder(Order orderToDiscontinue, Concept reasonCoded, Date discontinueDate, Provider orderer,
Encounter encounter) throws Exception
OrderService.discontinueOrder(Order orderToDiscontinue, String reasonNonCoded, Date discontinueDate, Provider orderer,
Encounter encounter) throws Exception
throw Exception ?
I see that the OrderServiceImpl wouldnt need to, if it wasnt for the interface.
Am interested into why this is and what a dev should do with it when using these methods?
Most methods in the openmrs API throw APIException which can be caught and dealt with but why choosing a so general Exception
Thanks!!
lluismf
(Lluis Martinez)
July 30, 2016, 6:50pm
2
Probably a bug, throwing Exception is rarely justified.
teleivo
(Ivo Ulrich)
July 30, 2016, 9:26pm
4
Ahh, we just released openmrs 2.0.0
I guess this can only be removed in a major release since its part of the method signature.
Should an issue to remove this be created?
lluismf
(Lluis Martinez)
July 30, 2016, 9:51pm
5
I believe that if someone is catching it in a controller and you remove it from the signature nothing will happen (it will still compile). Because Exception includes both checked and runtime.
teleivo
(Ivo Ulrich)
July 31, 2016, 10:03am
6
thanks @lluismf !
@darius what do you think, should we remove throws Exception
from OrderService.discontinueOrder
As a side note:
I see that the checkstyle doesnt prevent this type of throws
should this checkstyle config also be adjusted.
I think currently checkstyle is not configured to break the build on Travis CI (it doesnt run on PRs), should it?
lluismf
(Lluis Martinez)
August 1, 2016, 11:10am
7
1 Like
teleivo
(Ivo Ulrich)
August 1, 2016, 11:59am
8
am I now allowed to call myself “analog sonar”
wyclif
(Wyclif Luyima)
August 1, 2016, 2:37pm
9
I do agree that Exception is too generic, I believe the undocumented convention is to add throws APIException to service methods and DAOException to DAO methods. Since these are unchecked exceptions this leaves the API backwards compatible even when new exceptions are thrown from service methods as long as they are of the same type or a sub type. But of course another person might urgue that we can then get rid of the throws clause since they are unchecked exceptions.
darius
(Darius Jazayeri)
August 2, 2016, 4:39pm
11
+1 to just switching it to throws APIException in the next maintenance
release.
I agree with Lluis that this just adds noise, but I wouldn’t bother
changing that in just one method, if it’s the convention everywhere else.
-Darius (by phone)
teleivo
(Ivo Ulrich)
August 2, 2016, 5:26pm
12
created ticket https://issues.openmrs.org/browse/TRUNK-4909
with Fix Version/s: Platform 2.0.1