Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: exception handling problem

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Thanked 0 Times in 0 Posts

    Default exception handling problem

    Design and implement a program that creates an exception class called
    InvalidDocumentCodeExeception, designed to be thrown when an improper designation
    for a document is encountered. during processing. Suppose in a particular business
    all documents are given a two-character designation starting with either U, C, or P,
    standing for unclassified, confidential, or proprietary. If a document designation is
    encountered that description, the exception is thrown. Create a driver program to test
    the exception, allowing it to terminate the program.


    Modify the solution to PP 10.3 (above) such that it catches and handles the exception
    if it is thrown. Handle the exception by printing the appropriate message and then
    continue processing.


    anyways i've completed Programming Projects 10.3 and 10.4, the code is below
    however I have no idea what this other stuff is about :

    For this lab you will combine Programming Projects 10.3 and 10.4 in your
    textbook on pages 580 and 581.
    You solution should include a “Driver” program that tests the exception. To do
    this, you will need to create a class that holds information about Documents you
    are processing. You may choose what that document contains (ie: Vendor Name,
    Total Sale, Client Name, Type of Lawsuit, ……. You choose, but it must include
    Document Code).
    Your “Driver” program should include a loop so the user can enter information for
    a number of documents. Use an Array to hold the Document Objects.
    Entering an improper Document Code should trigger the exception. Your code
    should handle the exception, and allow the user to enter more documents.
    When the user is done entering Document information, print the contents of your
    Extra Credit: sort your array before printing.

    can someone please tell me what its asking and how to implement it
    cuz I have no idea :S

    any help will be much appreciated




    public class InvalidDocumentCodeException extends Exception{
    public InvalidDocumentCodeException(){
    public String getMessage(){
    return "Document code must be U (Unclassified), C (Confidential), or P (Proptietary)." +
    "\nDocument will default to Unclassified.";

    public class Document {
    private String dType = "U";
    public Document(String docType){
    if( docType.compareToIgnoreCase("U") != 0
    && docType.compareToIgnoreCase("C") != 0
    && docType.compareToIgnoreCase("P") != 0 )
    throw new InvalidDocumentCodeException();
    dType = docType;
    catch(InvalidDocumentCodeException e){
    System.out.println("Exception caught and handled! Continuing...");
    public void setDocType(String docType){
    dType = docType;
    public String toString(){
    return "Document type: "+ dType.toUpperCase();

    import java.util.Scanner;
    public class Starter {
    public static void main(String[] args) {
    String done = "DONE";
    System.out.println("DocType? U = Unclassified, C = Confidential, P = Proprietary.");
    System.out.println("Type DONE, in all caps to end.");
    Scanner scan = new Scanner(System.in);
    String docType = scan.next();
    while(docType.compareTo(done) != 0){
    Document doc = new Document(docType);
    docType = scan.next();
    System.out.println("Program Fin~");

  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Washington, DC
    My Mood
    Thanked 698 Times in 595 Posts

    Default Re: exception handling problem

    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

  3. #3
    Registered Users javapenguin's Avatar
    Join Date
    May 2010
    North Central Illinois
    My Mood
    Thanked 112 Times in 110 Posts

    Default Re: exception handling problem

    What part are you having trouble with?

    The Exception class part, the array part, the sorting part (which is extra credit anyway), how to appropriately handle the exception, the entire thing, something else?
    Please mark solved threads as "Solved" by going to threads and clicking "Mark Solved"
    Using code tags

    How To ask questions the smart way
    Java Tutorials
    Java API
    Save Our Snips
    Hit THANKS to thank a person. Hit REP+ to increase reputation (or decrease it). Cannot give to same person for a while.
    Shooting Park Road Baptist Church Site

Similar Threads

  1. [SOLVED] exception handling
    By Topflyt in forum Exceptions
    Replies: 5
    Last Post: December 22nd, 2011, 12:00 PM
  2. [SOLVED] Exception Handling
    By Melawe in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 21st, 2011, 07:39 PM
  3. Exception handling
    By JavaGirl9001 in forum Object Oriented Programming
    Replies: 1
    Last Post: November 26th, 2011, 08:45 PM
  4. Exception Handling
    By hello_world in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 5th, 2011, 06:47 PM
  5. Exception handling
    By AnithaBabu1 in forum Exceptions
    Replies: 6
    Last Post: August 27th, 2008, 10:37 AM