aspose file tools*
The moose likes Beginning Java and the fly likes Throwing and Catching Exceptions... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Throwing and Catching Exceptions..." Watch "Throwing and Catching Exceptions..." New topic
Author

Throwing and Catching Exceptions...

Dawn Allestad
Greenhorn

Joined: Aug 30, 2003
Posts: 12
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 ]
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
"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.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Aug 30, 2003
Posts: 12
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
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1821

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?


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Dawn Allestad
Greenhorn

Joined: Aug 30, 2003
Posts: 12
Sorry... but what's an IDE?
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Dawn Allestad
Greenhorn

Joined: Aug 30, 2003
Posts: 12
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

Joined: Aug 30, 2003
Posts: 12
I'm using JGrasp.
Dawn
Dawn Allestad
Greenhorn

Joined: Aug 30, 2003
Posts: 12
BTW, just a quick additional question... how close is visual basic to java?
Are they similar?
Dawn
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Not even close. They're not similar at all.


[Jess in Action][AskingGoodQuestions]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
What does the Employee class look like? Is it on the classpath?
Dawn Allestad
Greenhorn

Joined: Aug 30, 2003
Posts: 12
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

Joined: Aug 30, 2003
Posts: 12
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

Joined: Aug 30, 2003
Posts: 12
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
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
I guess talking about with all of you made me think it through.
It often does. See http://c2.com/cgi/wiki?CardboardAnalyst


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Throwing and Catching Exceptions...