|
-
constructor
hey...
i am working on a program in which i have to write a program that shows a constructor passing information about constructor failure to an exception handler. i have my code compiling and running....but for some reason it wont print the information in my catch block. i thought my try block's info was false so it should get into the catch block. plz help asap!!! i'm stuck.
here is my code....
public final class InRange {
// aName has content.
// exception IllegalArgumentException if a param does not comply.
public InRange ( String aName, double aSpeed ) {
if ( !textHasContent(aName) ) {
throw new IllegalArgumentException("Name has no content.");
}
if ( aSpeed < 0.0 || aSpeed > 1.0 ) {
throw new IllegalArgumentException("Speed not in range [0..1]: " + aSpeed);
}
fName = aName;
fSpeed = aSpeed;
}
private String fName;
private double fSpeed;
// Returns true if aText is non-null and has visible content.
private boolean textHasContent( String aText )
{
String emptyString = "";
return (aText != null) && (!aText.trim().equals(emptyString));
}
public static void main(String args[])
{
// InRange part;
IllegalArgumentException row=null;
String row1 = null;
String string1="Sabeen";
String emptyString1 = "";
try
{
row1 = string1;
}
catch(IllegalArgumentException ex)
{
System.out.println("Empty string causes an exception.");
}
System.out.println("main: " + InRange.class.getName() + " ended");
}
}
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