Results 1 to 3 of 3
Thread: exception
- 03-22-2008, 09:45 PM #1
Member
- Join Date
- Mar 2008
- Posts
- 6
- Rep Power
- 0
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();
Where and how do i have to define this IllegalArgumentException so that it can print a certain message??Java Code:try{ ... .. } catch(NumberFormatException e) { throw new IllegalArgumentException(); }
- 03-22-2008, 11:28 PM #2
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:
Pretty easy, right? ;)Java Code:... throw new IllegalArgumentException("Exception: cannot execute."); ...Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? Vote now!
Got a little Capt'n in you? (drink responsibly)
- 03-23-2008, 07:01 PM #3
Member
- Join Date
- Mar 2008
- Posts
- 6
- Rep Power
- 0
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...
Java Code:public class GeometricFigure{ private String name; public GeometricFigure(String ime) { this.ime = ime; } public String getName() { return this.name; } }how can i make the bolded part print "Exception" when i call for exampleJava 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] }
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...?Last edited by Oktam; 03-25-2008 at 12:23 PM. Reason: deadline
Similar Threads
-
Need help on Exception
By Deon in forum New To JavaReplies: 7Last Post: 02-11-2010, 05:46 PM -
Where does the exception go?
By aytidaalkuhs in forum New To JavaReplies: 3Last Post: 04-07-2008, 02:24 PM -
Trouble with factory method - unhandled exception type Exception
By desmond5 in forum New To JavaReplies: 1Last Post: 03-08-2008, 06:41 PM -
JSP Exception Hanling
By Java Tip in forum Java TipReplies: 0Last Post: 12-24-2007, 09:57 AM -
Exception
By Camden in forum New To JavaReplies: 2Last Post: 11-26-2007, 11:50 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks