-
exception
I'm new to java and got an exception problem...if an exception occurs in my programme i must print the output "can't execute", but with using a new exception: throw new IllegalArgumentException();
Code:
try{
...
..
}
catch(NumberFormatException e) {
throw new IllegalArgumentException();
}
Where and how do i have to define this IllegalArgumentException so that it can print a certain message??
-
The Sun tutorials show you one way to perform an output upon a thrown exception. There's also another way(as stated in the API for IllegalArgumentException - yes, exceptions have an API page too :) ) which is not much different from your existing code:
Code:
...
throw new IllegalArgumentException("Exception: cannot execute.");
...
Pretty easy, right? ;)
-
Tnx Capt :)...but...it seems i didn't define my problem well enough...here goes.. i'll put a part of my programme here...i made a few classes... one extends the other...
Code:
public class GeometricFigure{
private String name;
public GeometricFigure(String ime) {
this.ime = ime;
}
public String getName() {
return this.name;
}
}
Code:
public class Line extends GeometricFigure {
public Line(int x0, int y0, int x1, int y1) {//coordinates
super("Line");
this.x0 = x0;
this.y0 = y0;
this.x1 = x1;
this.y1 = y1;
}
...
..
..
[I]public static GeometricFigure fromStringArray(String[] params) throws IllegalArgumentException{
try{
int arg_x0 = Integer.parseInt(params[0]);
int arg_y0 = Integer.parseInt(params[1]);
int arg_x1 = Integer.parseInt(params[2]);
int arg_y1 = Integer.parseInt(params[3]);
return new Line(arg_x0, arg_y0, arg_x1, arg_y1);
}[B]
catch(NumberFormatException e)
{
throw new IllegalArgumentException();
}[/B]
}[/I]
}
how can i make the bolded part print "Exception" when i call for example
GeometricFigure figure = Line.fromStringArray(subarray); from some other function from somewhere (one of the elements of subarray is a string).
... how to make it work ... help :confused:
EDIT: anyone...?