• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

configuration dialog restart when error in constructing the application

 
Norbert Lebenthal
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

I'm not far from being done with coding of my SCJD app, but there's something I don't manage to get clean: what to do in case of bad configuration. For example if the file given for the db is not a proper db file. In fact, what to do is easy: to relaunch the dialog

the question is how to that nicely.

Up to now, I've a enum handling the various modes (figuring the proper one from the main arguments). Something like:


however, if the config is broken, how to rerun it ?

I could have a "protected boolean doRun()" un LaunchMode, expecting a boolean to say whether it was successful or not (and restart if not) but I really find it ugly (comes from nowhere => hard to get for a newcomer imho).

The run() could call itself again in case of configuration failure, but it could lead to a stackoverflow. It's unlikely I agree but still I find it not nice neither...

someone with a better option ?

 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, Nono. Still struggling with the exceptions?

The thing is that you don't have to rerun anything. How about doing something like this:



Please take a look at that and let me know if it helps!
 
Roel De Nijs
Sheriff
Posts: 10603
143
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Norbert,

I kept it simple: wrong configuration settings will result in an appropriate error message and the application exits (after user clicks 'ok' in the error message dialog).

Kind regards,
Roel
 
David Byron
Rancher
Posts: 175
Clojure Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norbert Lebenthal wrote:what to do in case of bad configuration. For example if the file given for the db is not a proper db file. In fact, what to do is easy: to relaunch the dialog

the question is how to that nicely.


I implemented a dialog restart by doing something like this:



Code like this occurs in a promptForClientOptions() method that builds my ClientOptionsDialog (called "options"). So if (for example) the database chosen is invalid, the exception handling code offers a warning, nukes the existing dialog, and calls promptForClientOptions(), the method in which it resides.

Norbert Lebenthal wrote:The run() could call itself again in case of configuration failure, but it could lead to a stackoverflow. It's unlikely I agree but still I find it not nice neither...


Sure, it replaces an existing dialog with a new one on each iteration, but that's (a) simple, and (b) no more strange than constructing a new TableModel every time a value in its state changes. ;)

Anyone who restarts a simple dialog enough times to max out the stack probably shouldn't be allowed into the app anyhow. ;)
 
Norbert Lebenthal
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks all for your answers and especially Roberto Perillo: your solution is so damn clean !!! lovely It makes me wonder what I've been thinking about all this time, even if it looks like David Byron was quite close from my thinking path (I thought as well of exceptions, but I found them even less clean: handling exceptions by displaying message and then sending some other again, doesn't feel this clean).

thanks again

it's now all implemented and running fine
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool, Nono! Glad I could help!

Norbert Lebenthal wrote:it's now all implemented and running fine


Alright! So you're pretty close to being a SCJD! Good luck, champion!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic