imlearning
asked on
Need Help w/ Exception handler
Hey everyone here is my assignment for an online class im taking
Write a program that shows a constructor passing information about constructor failure to an exception handler. Define class SomeException, which throws an Exception in the constructor. You program should try to create an object of type SomeException, and catch the exception that is thrown from the constructor.
I wanted to get some input on my code to know if im following the assignment spec, it is hard to learn straight from abook w/o any input if you know what i mean.
class SomeClass
{
public SomeClass()
throws Exception
{
throw new Exception();
}
}
import java.io.PrintStream;
public class Demo3
{
public Demo3()
{
}
public static void main(String args[])
{
SomeClass someclass;
try
{
someclass = new SomeClass();
}
catch(Exception exception)
{
System.out.println(excepti on.toStrin g());
}
}
Write a program that shows a constructor passing information about constructor failure to an exception handler. Define class SomeException, which throws an Exception in the constructor. You program should try to create an object of type SomeException, and catch the exception that is thrown from the constructor.
I wanted to get some input on my code to know if im following the assignment spec, it is hard to learn straight from abook w/o any input if you know what i mean.
class SomeClass
{
public SomeClass()
throws Exception
{
throw new Exception();
}
}
import java.io.PrintStream;
public class Demo3
{
public Demo3()
{
}
public static void main(String args[])
{
SomeClass someclass;
try
{
someclass = new SomeClass();
}
catch(Exception exception)
{
System.out.println(excepti
}
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
May i ask why?
Just saying, it's OOP and you should take advantage, does not say very much.
Mark
Just saying, it's OOP and you should take advantage, does not say very much.
Mark
Mark,
It is a line say to me by my profs when I was an undergrad......
also,
this way, you can always ensure your java files are resuseable.
It is way better then coding everything in main.
That's OOP.....
It is a line say to me by my profs when I was an undergrad......
also,
this way, you can always ensure your java files are resuseable.
It is way better then coding everything in main.
That's OOP.....
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ah..
Mark, I guess is just that T.A. in me... he never left the education sector.... lol
anyways, thanks.
and imlearning, hope you learn Java happily. It is a fun language to code in... especially how much it can actually do.
Mark, I guess is just that T.A. in me... he never left the education sector.... lol
anyways, thanks.
and imlearning, hope you learn Java happily. It is a fun language to code in... especially how much it can actually do.
I agree with you that the specification is a bit vague, but it doesn't sound all too difficult. Seems like you got it right.
Mark