Hi Sabra
,
I think you need to handle this error at jaggery level.
Considering a method returning a user object the client code should not be
> able to proceed further if there is no user.
In this case, -1 for returning NULL. When there is an error,
unless
it is recoverable locally you
*should*
convey it to the upper layers. In your case, If you cannot return a user
object it is more intuitive to return an exception such as
UserManagerException.
By returning NULL, you cannot make it mandatory to handle exception. Your
client code will not be aware of NULL unless the developer reads your
implementation class OR the documentation. Try to avoid
NullPointerException
as much as possible.
In your client code(Jaggery) you can catch this error with try{ }
catch(error){ }. Found this blogpost [1] which discusses on jaggery error
handling.
AFAIK Jaggery will wrap java exceptions with ScriptException object.
Regards,
Rasika
[1]
http://ruchirawageesha.blogspot.com/2013/04/error-handling-in-jaggery.html
On Tue, Jul 12, 2016 at 2:17 PM, Abimaran Kugathasan <[email protected]>
wrote:
> There are good enough discussion in Stackoverflow [1], [2] and [3]. You
> could return null, empty object or throw exception in the case of data not
> available.
>
> It's also depends on the type of the Object you are supposed to return, if
> it's a ArrayList/Map, then returning empty ArrayList/Map is better than
> returning null, but, in case of Model object, I think, returning null is
> better than retuning a mock object of that class.
>
>
> [1] :
> http://programmers.stackexchange.com/questions/120355/is-it-better-to-return-null-or-empty-values-from-functions-methods-where-the-ret
> [2] :
> http://stackoverflow.com/questions/1626597/should-functions-return-null-or-an-empty-object
> [3] :
> http://programmers.stackexchange.com/questions/228287/returning-null-or-a-empty-value-throw-exception
>
> On Tue, Jul 12, 2016 at 12:03 PM, Jayanga Kaushalya <[email protected]>
> wrote:
>
>> Hi,
>>
>> In my opinion, returning an empty object is far better. It will reduce
>> unnecessary null checks and will stop the code from going on different
>> paths. And code quality wise also I think returning empty is cleaner.
>> For example:
>>
>> *List list = getList();*
>>
>> *for (Item item : list) {// Do logic.*
>> *// This will not execute if the list is empty.*
>> *}*
>>
>> Is much cleaner than
>>
>> *List list = getList();*
>> *if (list == null) {*
>> *// Handle the logic.*
>> *// Now this is a different code path.*
>> *}*
>>
>> Thanks!
>>
>> *Jayanga Kaushalya*
>> Software Engineer
>> Mobile: +94777860160
>> WSO2 Inc. | http://wso2.com
>> lean.enterprise.middleware
>>
>> On Tue, Jul 12, 2016 at 10:05 AM, Sabra Ossen <[email protected]> wrote:
>>
>>> Hi Chamila,
>>>
>>> I checked from findbugs and it didn't return an error. Is returning an
>>> empty object a practice followed in WSO2?
>>>
>>> On Tue, Jul 12, 2016 at 9:25 AM, Chamila Wijayarathna <
>>> [email protected]> wrote:
>>>
>>>> Hi Sabra,
>>>>
>>>> AFAIK when we return a null from a method, find bugs show it as an
>>>> error (please check this) and to fix this we use empty objects. So I think
>>>> the returning null is not something we should do.
>>>>
>>>> Thank You!
>>>>
>>>
>>>
>>>
>>> --
>>> *Sabra Ossen*
>>> *Software Engineer*
>>> Email: [email protected]
>>> Mobile: +94 767 837356
>>>
>>> _______________________________________________
>>> Dev mailing list
>>> [email protected]
>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>
>>>
>>
>> _______________________________________________
>> Dev mailing list
>> [email protected]
>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>
>>
>
>
> --
> Thanks
> Abimaran Kugathasan
> Senior Software Engineer
>
> Email : [email protected]
> Mobile : +94 773922820
>
> <http://stackoverflow.com/users/515034>
> <http://lk.linkedin.com/in/abimaran>
> <http://www.lkabimaran.blogspot.com/> <https://github.com/abimarank>
> <https://twitter.com/abimaran>
>
>
> _______________________________________________
> Dev mailing list
> [email protected]
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>
--
With Regards,
*Rasika Perera*
Software Engineer
M: +94 71 680 9060 E: [email protected]
LinkedIn: http://lk.linkedin.com/in/rasika90
WSO2 Inc. www.wso2.com
lean.enterprise.middleware
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev