• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

School project help

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


TEST PROGRAM



Why will by throw exception not work? when I try this code in a test program I get the error:

unreported exception Exception; Must be caught or declared to be thrown
 
Marshal
Posts: 76854
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Start by going through the Java™ Tutorials about exceptions, particular where it says catch or notify. If you throw a plain simple Exception, that is checked, and the compiler will force you to handle it somehow. Otherwise the program will not compile.
 
Rancher
Posts: 1059
27
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not only follow the sage advice already given, but what IDE do you use? It seems to me that my NetBeans IDE tells me what exception needs to be caught while I am coding.
 
Chris McBurn
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I left out the throw exception out and just used a if-else println error... I think it's in the requirements of my assignment to use a throw exception but I don't know how to get it to work.
 
Sheriff
Posts: 7123
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exceptions must be caught or declared. To catch them, use try/catch. To declare them, put a throws clause in the method declaration.
 
Chris McBurn
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a throws clause at the top of the method?
 
Knute Snortum
Sheriff
Posts: 7123
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
True, but exceptions "bubble up" so you need catch or declare the exception in MovieAccountTest.
 
Campbell Ritchie
Marshal
Posts: 76854
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Never use == true or == false which are not only poor style but also error‑prone. If you write = by mistake you can get two logic errors for the price of one.
Not
if (b == true) ...
but
if (b) ...
Not
if (b == false) ...
but
if (!b) ...
You have much repeated code in that snippet; lines 6-19 are almost identical to lines 23-37. Don't use decimal format. That was superseded by Formatter over eleven years ago. Don't use \n unless somebody tells you they need an LF character. Use printf and the %n tag. Don't use += for Strings. That has poor performance, though you won't notice until you use it many times. Use + instead.
 
Sheriff
Posts: 8515
615
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And probably you want to simplify your method "streamMovie" which does all sort of things which are not related with the method name.

And since it is a school assignment, you suppose to successfully loose some marks of not using right methods for the right tasks (one task per one method). Actually you have been told that by Campbell R., who said you're repeating yourself by writing duplicated code - it is actually the same thing just in different words, which requires the same approach in order to fix it.
So, if you see you write duplicated code - make it separate method and reuse. If you see you write code which is not streaming movie - move that code away and make a method, then use it.

Package name according to the Java convention suppose to start be in lower cases (you have differently at the moment).
 
I wish to win the lottery. I wish for a lovely piece of pie. And I wish for a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic