Handling Excerption

42 views
Skip to first unread message

Franck Facchetti

unread,
Feb 23, 2015, 1:23:00 PM2/23/15
to jrebirt...@googlegroups.com
Hi Seb,

Congratulations for your new born child !

I just discovered your framework, and by reading the documentation i was wondering what's the best approach to handle exceptions occurring in Service ?

Regards,
Franck. 

Sebastien Bordes

unread,
Feb 23, 2015, 2:28:42 PM2/23/15
to jrebirth-users
Thank you Franck,

I'm pleased to count you among JRebirth users.

I don't know which kind of exceptions occur in your application but the best way is certainly to call a specific Command that will warn the user. It could be a modal dialog showing the exception or an user-friendly one that explain what had gone wrong, or another command that can fix the trouble (re-connection of connection has been lost).

I have started a dialog module that will used custom command and service used to open dialog by abstracting the dialog implementation, let me know if you are interested in.

Seb

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "JRebirth Users".
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse jrebirth-user...@googlegroups.com.
Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.



--

Franck Facchetti

unread,
Feb 23, 2015, 3:13:20 PM2/23/15
to jrebirt...@googlegroups.com
It's my fault, I should have been more precise.
What I wanted to say is that I have a service that sends an exception. I would have expected to receive the Wave with the status FAILED, but this is not the case. Is this a bug ? Or may be i just misunderstood the documentation? 

Sebastien Bordes

unread,
Feb 23, 2015, 5:45:26 PM2/23/15
to jrebirth-users
Currently the wave status is marked as failed only when the service method call has failed.

} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
            LOGGER.log(SERVICE_TASK_ERROR, e, getServiceHandlerName());
            this.wave.status(Status.Failed);
        }

Other Exceptions are not caught, so you have the option to catch them and mark the source wave as failed by yourself.


Could you tell me more abour the exception you want to manage ? Is it a busines one or a technical one ?

Perhaps I should handle all exceptions or a custom hierachy (like JRebirthServiceException)....

Franck Facchetti

unread,
Feb 24, 2015, 4:29:38 AM2/24/15
to jrebirt...@googlegroups.com
Hi,

It's a technical exception (UnknowHostException).
My use case :
- A Command call a Service dedicated to read a list of RSS Feeds. A ProgressBar is updated during the process.
- The Service failed for any reason (Connection is broken, Proxy denies access, ...)
- The Exception is catched and the ProgressBar's color is switched

This line of code is never reached :
this.wave.status(Status.Failed);
There seems to be a DVELOPER MODE involved ?

I tried to mark the wave as FAILED by myself, but the wave that i receive in return is mark as CONSUMED.

Sebastien Bordes

unread,
Feb 24, 2015, 6:14:40 AM2/24/15
to jrebirth-users
The algo is:

When the service method is called:

When the return type of the method is VOID, no wave is sent
When the return type is null or a valid object, a wave is sent

If the service method is not found, (because the method doesn't exist or bar arguments are used), the source wave is marked as failed and no return wave is sent, in this case if the DeveloperMode is activated a CoreRuntimeException is thrown to warn developer that something is going wrong.

If another exception is thrown, nothing is done so it will be propagated to higher level and probably caught by UncaughtExceptionHandler.


According to provided info:
You catch the UnknowHostException into the service method, and you mark the source wave as failed, but you are still returning something so a return wave is sent at the end

What do you want to do when this kind of exception occurred ?


Possible workaround:

I don't want to catch generic Exception because it can mask real troubles, but I can update JRebirth to handle a custom ServiceException (extending RuntimException)

So you can catch UnknowHostExceptionand and wrap it into a ServiceException, you can call a Command to do something (like opening a Information Dialog), then you can trhow the wrapped Exception.

I will update the related code


Seb 

Franck Facchetti

unread,
Feb 24, 2015, 2:19:11 PM2/24/15
to jrebirt...@googlegroups.com
When the return type of the method is VOID, no wave is sent
Wow ! I missed something there.

Wouldn't be more intuitive to do this :
WaveType DO_SOMETHING = Builders.waveType("SOMETHING"); // A basic wave definition
WaveType DO_SOMETHING = Builders.waveType("SOMETHING").returnAction("SOMETHING_DONE"); // I want to be warned when service has finished
WaveType DO_SOMETHING = Builders.waveType("SOMETHING").returnAction("SOMETHING_DONE").returnItem(SOME_SERVICE_RESPONSE); // I want to be warned and get the result

In the same frame of mind, something like follow to handle exception :
WaveType DO_SOMETHING = Builders.waveType("SOMETHING").onError("ERROR_WAVE"); // Send a wave when an exception occure
WaveType DO_SOMETHING = Builders.waveType("SOMETHING").onError(SomeDummyException.class, "SPECIFIC_ERROR_WAVE"); // Send a wave when an certain kind of exception occure

I know you don't want to spam other component and that i could use WaveListener, but I think having both implementations and let the developers which ones to adopt would be good.
What do you think ?

Regards,
Franck.

Sebastien Bordes

unread,
Feb 24, 2015, 3:27:17 PM2/24/15
to jrebirth-users
The 2 ideas are quite interesting, I think that you have read an old mail where I adviced to use WaveListener to be informed when the wave process had been achieved.
At this time wave creation was not using a fluent API like now, so we have now new perspective to be more reactive.

I will enter 2 issues on Github for 8.0.1 version to track these enhancements. I will probably refine the rules and update the documentation accordingly.
The second one has a bigger impact because it concerns also all others Wave Handling.

Merci Franck !

Franck Facchetti

unread,
Feb 24, 2015, 4:15:42 PM2/24/15
to jrebirt...@googlegroups.com
Thanks for your time and patience.

I'll follow those issues with interest !

I'll come back soon with more questions about your interresting framework...

A bientôt !

Sebastien Bordes

unread,
Feb 25, 2015, 4:28:21 AM2/25/15
to jrebirth-users
The first issue is Fixed: https://github.com/JRebirth/JRebirth/issues/141

You can find an usage example into MasteringTables latest commit: https://github.com/JRebirth/MasteringTables/commit/110beda2e4cc89ab0dbdf2509bd6d036517f300b where a boolean has been replaced by a void

Build is running on ci.jrebirth.org

I will work on the second tonight

Seb

Sebastien Bordes

unread,
Feb 26, 2015, 3:12:56 AM2/26/15
to jrebirth-users
The second fix has been pushed yesterday,  https://github.com/JRebirth/JRebirth/issues/142

You can use onException(...) to define which Exception should be handled by a Wave or a Command.

Currently it only works with ServiceTask.

You can grab the latest 8.0.1-SNAPSHOT from OJO to test it.

Seb
Reply all
Reply to author
Forward
0 new messages