-
Errors with Exceptions
Here is my code that had the problem.......
Rationals.java:16: unreported exception java.lang.Exception; must be caught
or declared to
be thrown
throw new Exception(" Zero in denominator.");
^
1 error
Here is the error i get......
public Rationals(int num, int den){
if(den == 0){
throw new Exception(" Zero in denominator.");
}
numerator = num;
denominator = den;
if (denominator < 0){
numerator *= -1;
denominator *= -1;
}
}
PLEASE HELP!!!!!!!!
-
Re: Errors with Exceptions
In the method header you should say which Exceptions your method might throw.
Just add this to your method header
public Rationals(int num, int den) throws Exception {
it would be a better practice if you define your own exception, DividedByZeroException
and then throw it if your test fails.
Ako
"Lindsey" <Zave4@aol.com> wrote:
>
>Here is my code that had the problem.......
>
>Rationals.java:16: unreported exception java.lang.Exception; must be caught
>or declared to
>be thrown
> throw new Exception(" Zero in denominator.");
> ^
>1 error
>
>
>
>Here is the error i get......
>
> public Rationals(int num, int den){
> if(den == 0){
> throw new Exception(" Zero in denominator.");
> }
> numerator = num;
> denominator = den;
> if (denominator < 0){
> numerator *= -1;
> denominator *= -1;
> }
> }
>PLEASE HELP!!!!!!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks