codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Im trying to creat an exception class  alainap21 at 21:27 on Sunday, March 26, 2006
 

i have a program that has an exception class called StringTooLongException. I also have a class called InputString. I want to prompt the user to input a series of characters and when the user is done they will enter DONE. My exception class is supposed to see if the string is greater than 20 characters. If its greater than 20, it will throw the problem and print a message. Here is what i have....

import java.util.Scanner;
public class InputString
{
public static void main(String[]args) throws Exception
{

final int MAX=20;
String str;
int num;

Scanner scan = new Scanner(System.in);
StringTooLongException problem = new StringTooLongException("Input String is too long."); //******i get an error here saying it can't find the constructor****/
System.out.println("Enter a string of characters" + "When finsihed type DONE");
str = scan.nextLine();

while (!str.equals("DONE"))
{
try
{
num = Integer.parseInt(str);
if(num > MAX)
throw problem;//****error here...saying incompatible types...required "Throwable"*****/
}
catch(StringTooLongException problem)
{
System.out.println("Input String is too long.");
}

}
System.out.println("End of main method.");
}

}

public class StringTooLongException extends Exception
{

StringTooLongException(String message)
{
super (message);
}
}

  Re: Im trying to creat an exception class  crwood at 22:41 on Sunday, March 26, 2006
 


import java.util.Scanner;

public class InputString
{
public static void main(String[]args) throws StringTooLongException
{
final int MAX=20;
String str = "";
int num;

Scanner scan = new Scanner(System.in);

while (!str.equals("DONE"))
{
System.out.println("Enter a string of characters" + "When finsihed type DONE");
str = scan.nextLine();
num = str.length();
if(num > MAX)
throw new StringTooLongException("length " + num +
" > " + MAX);
}
System.out.println("End of main method.");
}
}

class StringTooLongException extends Exception
{
StringTooLongException()
{
super();
}

StringTooLongException(String message)
{
super (message);
}
}


  Re: Im trying to creat an exception class  dabora at 07:36 on Friday, March 25, 2011
 

The antidote to stress and its manifestations is relaxation. To relax is to rest deeply. Relaxation is a state in which there is no effort, and the brain is quiet. Dr. Herbert Benson MD., who coined the phrase "The Relaxation Response" describes the physiological and mental responses that occur when one consciously relaxes by saying that relaxation is the physiological state characterized by a slower heart rate, metabolism, rate of breathing, lowered blood pressure, and slower brain wave patterns.
_________________________________________

pass 4 sure| pass4sure security+| pass4sure ccnp| pass4sure cissp| pass4sure a+| pass4sure ccda| pass4sure network+| pass4sure ccie| pass4sure itil| pass4sure ccsp


  Re: Im trying to creat an exception class - TRY CATCH  rasengan at 05:25 on Wednesday, March 30, 2011
 

import java.util.Scanner;

public class InputString
{
public static void main(String[]args) throws Exception
{

final int MAX=20;
String str = "";
int num;

Scanner scan = new Scanner(System.in);

while (!str.equals("DONE"))
{
StringTooLongException problem = new StringTooLongException("Input String is too long.");
System.out.println("Enter a string of characters" + "When finsihed type DONE");
str = scan.nextLine();
num = str.length();
try
{

if(num > MAX)
throw problem;
}
catch(StringTooLongException ex)
{
System.err.println("Input String is too long.");
}

}
System.out.println("End of main method.");
}

}

class StringTooLongException extends Exception
{

StringTooLongException(String message)
{
super (message);
}
}









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  how do you think about this zencart site?
•  Student program by Perl [HELP me, plz]
•  Re: Walk With Walter for UNICEF Sponsorship
•  the International Organization
•  VB 100 test
•  a recertification process
•  manufacturing options
•  Google Apps
•  best practices and technology


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2011