Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Coffee corner » Raise Exception instead of ASSERT for container
Re: Raise Exception instead of ASSERT for container [message #12056 is a reply to message #12035] Tue, 09 October 2007 20:36 Go to previous messageGo to previous message
tvanriper is currently offline  tvanriper
Messages: 85
Registered: September 2007
Location: Germantown, MD, USA
Member
Another alternative (one I suggested in my original response, but perhaps too subtly) to using exceptions is to simply perform your request for the object within your multi-dimensional array, then test to see that the object is valid. If it is, it was within bounds. If not, you were outside of bounds (the array purposefully gave you a kind of object that is not valid, to give you a hint that you attempted an illegal operation... 'Value' objects have state to indicate error conditions in U++, and are perfect for this kind of thing).

No need to test to see if you're within bounds using this kind of code. Just test to see if the item you requested from the array is valid.

Such code is easier to read, in my opinion, than exceptions, which have a way of disrupting the flow of the code, sometimes in very undesirable ways (e.g. you were compelled to use a 'new' statement, and the exception has now caused your object to become dereferenced).

But, as we both seem to agree, this sort of thing may be a matter of personal preference. I think I've seen other examples of code where exceptions are enabled as an option; perhaps such code is appropriate here.
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: downloadable U++ manual
Next Topic: Vista.....
Goto Forum:
  


Current Time: Thu May 09 12:24:10 CEST 2024

Total time taken to generate the page: 0.01929 seconds