• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OOP-2 (NaturalLanguageMultiply)

 
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps the requirements should be clarified a bit on this one, as far as the specifics for throwing the Exception.
The way I initially threw/caught the exception worked great - it met all the requirements mentioned in the assignment specs, including outputting the exact text not recognized. I just didn't explicitly throw the exception from within a conditional in the toInt method. Instead, I declared that toInt throws Exception (as required by signature specs), and simply called it from within a try/catch block. In the catch portion, I built the error message, specifying the unrecognized string culprit.
To me, this was fine, but I still got the nit "Where is the exception you are creating (with text) and throwing?" mentioned at the end of my toInt method. I was relying on the fact that the exception was thrown whenever toInt was passed an unrecognized string, without having to use conditionals to determine whether or not a string was in the map.
I guess the purpose of this message is to alert students to the fact that you can save yourself a nit by not doing it the way I did at first. Or perhaps the specs for the assignment should state that the exception MUST be created and explicitly thrown in the toInt method.
------------------
  • Ryan Burgdorfer
  • Java Acolyte
 
tumbleweed
Posts: 5089
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did the same Ryan
  • Johannes de Jong
  • Mr. Plotzeling

 
Trailboss
Posts: 23778
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you were doing was to print your error message and terminate the program within the middle of the method.
What we would like to see is you generating an exception which percolates up to the main() method, where the problem is reported and the program ends naturally.
 
reply
    Bookmark Topic Watch Topic
  • New Topic