• 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

Throwing and Catching Exceptions...

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Forgive me if this is the wrong place to post this. I'm a green horn not only to the board but to java too. I'm trying to learn how to throw and catch an exception and found a program that does it, but I just can't seem to compile it. I know it's something really simple, but I can't figure it out. I'd appreciate any feedback I can get! Remember I'm a green horn so forgive my ignorance!
Here's the code:

Here's the second:
[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ August 31, 2003: Message edited by: Dirk Schreckmann ]
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"mightymucko",
Welcome to JavaRanch! We don't have many rules here, but one that we do have that we try to adhere to is a naming convention. Please change your display name to conform to these guidelines. Thanks for your cooperation, and we look forward to seeing you around the Ranch.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by mightymucko:
but I just can't seem to compile it.


No problemo. Can you paste the reason it won't compile? It'd help a lot, thanks.
Dave
 
Dawn Allestad
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry about that! See I told you I was a greenhorn!
When I compile it it keeps high lighting Employee in the ThrowEmployee program. I have both programs saved in my bin, and both opened when I go to compile, so I don't know what the problem is.
thanks!
Dawn
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
DO you have any messages that print out in a console or console log? Usually those messages tell you what (or, at least, lead you in the general ditection of) the problem.
From your statements, I assume that you are using some sort of IDE. Which one are you using?
 
Dawn Allestad
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry... but what's an IDE?
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An Integrated Development Environment - a program which combines an editor, compiler, debugger and more into a single application. Something like Eclipse, IntelliJ IDEA, JBuilder etc.
 
Dawn Allestad
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have six errors. Here are the errors... they all have to do with Employee.

1. symbol : class Employee
location: class ThrowEmployee
Employee first = new Employee(111, 88.99);
2. symbol : class Employee
location: class ThrowEmployee
Employee second = new Employee(222, 5.59);

3.symbol : class Employee
location: class ThrowEmployee
Employee third = new Employee(333, 12.44);
Highlighted the Employee that is being shown as having an error. It continues like this through out my program.
Thanks! Sorry to be a pain!
Dawn
 
Dawn Allestad
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using JGrasp.
Dawn
 
Dawn Allestad
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
BTW, just a quick additional question... how close is visual basic to java?
Are they similar?
Dawn
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not even close. They're not similar at all.
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does the Employee class look like? Is it on the classpath?
 
Dawn Allestad
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a third employee program. This is my Employee class It's:
import java.io.*;
public class Employee
{
int idNum;
double hourlyWage;

public Employee(int id, double wage) throws EmployeeException
{
idNum = id;
hourlyWage = wage;
if((hourlyWage < 6.00) || (hourlyWage > 50.00))
throw (new EmployeeException(idNum + " " + hourlyWage));

}
}
I'm all confused now! This is what I'm trying to do:
Create an EmployeeException class whose constructor receives a string that consists of an employee's ID and pay rate. Create an Employee with two fields, idNum and hourlyWage. The Employee constructor requires values for both fields. Upon consturction, throw an EmployeeException if the the hourly Wage is less than $6.00 or over $50.00. Write a program that establishes at least three Employees with hourlyWages that are above,velow, and within the allowed range. Save the program as ThrowEmployee.java.
I have been working on this for so long that I'm seeing double! Sorry I fogot to add the Employee class. It totally slipped my mind.
 
Dawn Allestad
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Holy Mackeral, I got it to compile. Now the problem is it shows only two employee errors and not three. Back to the program....
Dawn
 
Dawn Allestad
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it! HALLELUJAH! Thanks so much for your help! I forgot to open my Employee class! DOH!!! Then it only gives two errors because the third one isn't an error! Great Googly Moogly! I guess talking about with all of you made me think it through. Thanks!
Dawn
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess talking about with all of you made me think it through.
It often does. See http://c2.com/cgi/wiki?CardboardAnalyst
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic