• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception chaining

 
Anna Hays
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, can someone help me out of my few of thoughts please? I am doing B&S.
1. I am chaining the exceptions from the DB class to the GUI classes, which has quiet a few layers. I am writing the GUI controller now. I found almost every block of code I write, I have to put it in a try clause. I am comfortable about that since that would be really safe that my program won't just explode the stacks in front of the user. But does anyone think if the exceptions are thrown too heavily or is it OK to do so??
2. I noticed that in the specs it says "It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user.", but in the DB.java interface, it only says matches the prefix. So what does "exactly match" really mean??
3. Does anyone use regex in their search function? I think it is very helpful but might not worth the trouble...
Thank you!
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anna
Originally posted by Anna Kafei:
Hi, can someone help me out of my few of thoughts please? I am doing B&S.
1. I am chaining the exceptions from the DB class to the GUI classes, which has quiet a few layers. I am writing the GUI controller now. I found almost every block of code I write, I have to put it in a try clause. I am comfortable about that since that would be really safe that my program won't just explode the stacks in front of the user. But does anyone think if the exceptions are thrown too heavily or is it OK to do so??

I don't think exceptions are thrown too heavily here. I think it depends on how we pass the information from the data layer to the gui layer about what went wrong. One approach can be to use a single custom exception class and change the message. My book method in business layer throws 5 exceptions like RecordCannotBeBookedException, RecordAlreadyBookedException, TimeAlreadyPassedException, RecordModifiedException, IOException, RecordNotFoundException.
But we do in the gui layer is catch all these and let know the CSR in a user freindly way by popping up a message on the screen or writing in a textfield in some place in the gui itself like say logpanel like that.

2. I noticed that in the specs it says "It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user.", but in the DB.java interface, it only says matches the prefix. So what does "exactly match" really mean??

The find method given in the interface cannot be used for the gui search requirement. We should implement the find given by them and also we should have our own find method where it does exact match. Ex: "Fred" matches "Fred", and not "fred" or "Fredo".

3. Does anyone use regex in their search function? I think it is very helpful but might not worth the trouble...

I too thought so and did not use. But I should have done that because I heard and read that its quite very powerful. It may not be worth the effort for the project, but it should very useful in future. I recommend to learn and use it if you did not start or do your search functionality because it might be very helpful in future.

Thank you!

Good Luck.
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anna,
1. I am chaining the exceptions from the DB class to the GUI classes, which has quiet a few layers. I am writing the GUI controller now. I found almost every block of code I write, I have to put it in a try clause. I am comfortable about that since that would be really safe that my program won't just explode the stacks in front of the user. But does anyone think if the exceptions are thrown too heavily or is it OK to do so??

Chaining exceptions as you do is a good idea IMO.
But you could distinct:
- system exceptions (unrecoverable/unexpected by the client) which could be thrown as RuntimeExceptions
- application exceptions (recoverable by the client, informative) passed to the client as checked exceptions.
It cannot be that bad, ... it's comparable to the way EJBs manage exceptions.
And it would help you to have less try..catch blocks in your GUI.
2. I noticed that in the specs it says "It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user.", but in the DB.java interface, it only says matches the prefix. So what does "exactly match" really mean??

That "Fred" matches "Fred", but not "fred" neither "Freddy".
This discussion may help you, especially if you follow the link suggested by George in that thread .
3. Does anyone use regex in their search function? I think it is very helpful but might not worth the trouble...

You don't need it.
Regards,
Phil.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Phil & Anna,

Anna:
3. Does anyone use regex in their search function? I think it is very helpful but might not worth the trouble...
Phil:
You don't need it.

Don't let Max catch you disparaging regular expressions Phil
It is true that you can build your submission without regular expressions. It is also true that using (or not using) regular expressions wont change your mark.
That being the case, this assignment can be the perfect opportunity to learn how to use regular expressions. After all you do have the time (and hopefully the interest) to do so. And you will then see how powerful regex is. Whereas if you wait until you have to use regex in your real job you may find that you don't have the time or the desire to learn it.
If you would like to read book about regular expressions in Java, there is a new book out called "Real World Regular Expressions with Java 1.4" which Max wrote. You can also read the JavaRanch review of this book.
Regards, Andrew
 
Anna Hays
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree that regex is very powerful. I only know the very basic but I already find it very helpful at work. I think it would solve the problem of having extra functions that does the exact match or non case sensitive search problem. But the problem is, do I allowed to add an extra method in the DB.java interface? And of course, having regex could mean the user can enter pattern as well, do you think this is a problem?
Does any one know some open source package for JSDK 1.3 that does the same thing as JSDK 1.4?? I tried the one recomended by the jakarta website, but when I substitude the patterns that work in 1.4, it ain't working for the one that the jakarta website.
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anna Kafei:
Does any one know some open source package for JSDK 1.3 that does the same thing as JSDK 1.4?? I tried the one recomended by the jakarta website, but when I substitude the patterns that work in 1.4, it ain't working for the one that the jakarta website.

- I thought we cannot use any 3rd party software, be it the open source or closed source in our SCJD assignment.
In my assignment, it says......
The final program must have no dependencies on any libraries other than those of the Java 2 Platform.

[ March 15, 2004: Message edited by: Vish Kumar ]
 
Anna Hays
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I know, this is not for the assignment. Just when talking of regex, it reminds me I need an extension to 1.3, 1.3 doesn't have regex out of the box.
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not know about the features of JDK1.4 regex.
Currently in our project, we use JDK1.3 with the foll. GNU library for Java RE on Windows.
http://mirrors.sunsite.dk/maven/gnu-regexp/jars/
The API and FAQs for this package can be obtained from
http://www.cacas.org/java/gnu/regexp/

We just use gnu.regexp.RE class in this package to verify the number of digits and the alphanumeric pattern in our customers's data. I am not sure if this GNU library is still supported by its developers. So far, it seems to be working fine in our live env...
[ March 16, 2004: Message edited by: Vish Kumar ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic