Exception question

My exception hierarchy is as follows: custom exception class
MyException extending Exception. and MySQLException extending
MyException.
Exception->MyException->MySQLException
Now consider following case:
If there is a method m1 that has scope in which calls to two methods
m2 and m3 are made. m2 throws MyException and m2 throws
MySQLException.
Now how should the throws clause look like ?
Should it be
1) m1() throws MyException, MySQLException or
2) m1 throws MyException
My choice in (2).
In short: when there are parent and child exceptions thrown in
implementation should we go with approach (2) always throw parent ?
Now another point is if there is a method m4() that calls m1(). Just
looking at the signature of m1() it seems that MyException is thrown
here. But how will the caller client would know that m1() throws
MySQLException in some condition and for other condition throws
MyException. If we go with approach (1), from the signature itself the
caller would know that there can be 2 separate exceptions that may be
thrown from method m1(). This can be a justification for approach(1) but I personally think javadoc with approach(2) is the way to go.
What do you think ?

My exception hierarchy is as follows: custom exception
class
MyException extending Exception. and MySQLException
extending
MyException.
Exception->MyException->MySQLException
Now consider following case:
If there is a method m1 that has scope in which calls
to two methods
m2 and m3 are made. m2 throws MyException and m2
throws
MySQLException.
Now how should the throws clause look like ?
Should it be
1) m1() throws MyException, MySQLException or
2) m1 throws MyException
My choice in (2).
In short: when there are parent and child exceptions
thrown in
implementation should we go with approach (2) always
throw parent ?
Now another point is if there is a method m4() that
calls m1(). Just
looking at the signature of m1() it seems that
MyException is thrown
here. But how will the caller client would know that
m1() throws
MySQLException in some condition and for other
condition throws
MyException. If we go with approach (1), from the
signature itself the
caller would know that there can be 2 separate
exceptions that may be
thrown from method m1(). This can be a justification
for approach(1) but I personally think javadoc with
approach(2) is the way to go.
What do you think ?I would go with (1) to make it clear that there are two different
exceptions that could be thrown, so the caller can choose to
handle them differently.:
try {
  m1();
} catch (MySQLException e) {
  handleSQLException();
} catch (MyException e) {
  handleOtherExceptions();
}The caller can still do this using method (2) but may not know
if he does not see it in the method declaration.

Similar Messages

  • Try-catch & throw Exception Question

    Method evenNumber can throw IOException, and the caller of method
    evenNumber (in this case, method evenNumberTest and method evenNumberTest2)
    should catch the IOException. Otherwise, it will have compile
    error as the one in method evenNumberTest2.
    My question is when I run the program, it will have output "catch evenNumberTest",
    but it doesn't output "throw testNumber" Why is that?
    I thought ""throw new IOException("throw testNumber");"" will print
    "throw testNumber" when it throws the IOException.
    So in what situation "throw testNumber" will print it out??
    Please advise. Thanks!!
    =======================================================
    import java.io.*;
    public class ExceptionTest
    private void evenNumberTest()
    {     try
         { evenNumber(2);
         catch(IOException e)
         { System.out.println("catch evenNumberTest");
    ExceptionTest.java:14: unreported exception java.io.IOException; must be caught
    or declared to be thrown
    {   evenNumber(2);
    ^
         private void evenNumberTest2()
    {     evenNumber(2);
    private void evenNumber(int x) throws IOException {
         if (x % 2 == 0)
         throw new IOException("throw testNumber");
    public static void main(String[] args)
    {     ExceptionTest e = new ExceptionTest();
         e.evenNumberTest();

    Exception messages aren't printed out when the
    Exceptions are thrown.
    They are only printed if you explicitly print them, or
    if you do not catch them.He is talking about this print statement within the catch block
    catch(IOException e)
    { System.out.println("catch evenNumberTest");

  • Stream Exception Question

    Hi all.
    Question: When there is an exception operating on a stream, does the stream automatically get closed, not allowing any operations to be performed on the stream in any catch blocks?
    If so, how does one "refresh" the stream to try again?
    thanx

    It depends on the actual signal the stream received. For example, a reset is generally recoverable. Other errors are not. The easiest thing to do is always ensure the stream is closed in a 'finally' clause.
    - Saish

  • General Stack Trace and Exception Question

    I hope this is the correct forum to post to ... well here goes...
    The Big Picture:
    I�m using the org.xml.sax package (along with their subsequent �helper� and �ext� packages) to parse huge XML files.
    Some references:
    DefaultHandler -> org.xml.sax.DefaultHandler (Default base class for SAX2 event handlers)
    CustomHandler -> mypackage.CustomHandler (which extends the above DefaultHandler)
    SAXException -> org.xml.sax.SAXException (thrown by many methods defined in the DefaultHandler)
    The story:
    I�ve made a class which extends the DefaultHandler class; (CustomHandler). The DefaultHandler class has a bunch of methods declared in it that I overwrite, which all claim to throw these SAXExceptions. My overwritten methods defined in CustomHandler had also been written to throw those SAXExceptions.
    My Overwritten Methods: (you�ll see why the �throw� part is commented a little later)
    //Methods in SAX DocumentHandler
        public void startDocument(){//throws SAXException{
        public void endDocument(){//throws SAXException{
        public void startElement(String uri, String localName, String qName, Attributes attrs){//throws SAXException{
        public void endElement(String uri, String localName, String qName){//throws SAXException{
        public void characters(char buf[], int offset, int len){//throws SAXException{
    The Code Executes like This:
    try{
         File xmlFile = new File(getFileName());
         CustomHandler myHandler = new CustomHandler();
         saxParser.parse(xmlFile, myHandler); //<- Important Line
         myHandler.reportSomeXmlInfoAboutTheFile(); //<- Ignore this command
    }catch(ParserConfigurationException pce){
                pce.printStackTrace();       
    }catch(SAXException sax){
                sax.printStackTrace();
    }catch(IOException ioe){
                ioe.printStackTrace();
    }Sample Stack Trace: (The ArrayIndexOutOfBoundsException was set up to be thrown for the sake of discussion)
    java.lang.ArrayIndexOutOfBoundsException: 5
    at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:691)
    at org.apache.crimson.parser.Parser2.parse(Parser2.java:337)
    at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:345)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:281)
    at saxparserexercise.DriverClass.exercise(DriverClass.java:58) //<- Last (un Native to ME � not java) execution stack point
    at saxparserexercise.Main.<init>(Main.java:38)
    at saxparserexercise.Main.main(Main.java:59)
    The Problem:
    Its about my stack traces� they all map through the above noted �Important Line� instead of through my overwritten methods in CustomHandler (where I cause the ArrayIndexOutOfBoundsException) So, therefore I thought I�d try commenting out those �throws SAXException� parts in the method declarations of my CustomHandler class� Diddn�t change a thing. Thus my question is�
    The Question:
    What changes or modifications can I make such that the Stack Trace I receive will map to exactly where the problem occurs in my code� does that make sense?

    I suspect it may be because your version of Catalina was compiled without debugger support. From what I remember this strips line numbers from generated class files.
    You'll need to download either a debug-enabled version of Catalina, or pull down the source and rebuild the system.
    Unless I'm barking up the wrong tree.
    J

  • Exception question! pls help

    i dont seem to get around the Java exception using the User-defined-exception classes.
    I have three classes OldException, TooYoungException and InvalidException.
    In my TooYoungException i have:
    public class AgeTooOldException
        extends ArithmeticException {
      public AgeTooOldException()
      public AgeTooOldException(String message)
        super ( message );
      }And in my main i have:
      try {
          String age = JOptionPane.showInputDialog("Please your age");
          int conAge = Integer.parseInt(age);
        catch (AgeTooOldException ato ) {
           if (conAge > 80) //if over 80 error
          JOptionPane.showMessageDialog( this,
                                         "Age is too old, must be less then 120",
                                         "Invalid age entered format",
                                         JOptionPane.ERROR_MESSAGE );
        catch (Exception x ) {
          JOptionPane.showMessageDialog(this, "Error has occurred");
        }I am doing something wrong, and i need some one to advise me what i did wrong, because i just dont seem to get the exception handling.

    This design is wrong.
    First of all, your AgeTooOldException should not extend ArithmeticException. If you read the javadocs, you don't have an ArithmeticException here, in spite of the fact that a number is involved. Extending Exception is enough.
    Second, you didn't write the exception class properly. Exception has four constructors. You should override them all.
    Third, you don't use exceptions like goto statements. They're not supposed to be for program control. They're supposed to signal conditions that the program cannot handle. This one is a bit on the fuzzy side of that line.
    If you insist on using your exception, do it like this:
    public class AgeTooOldException extends Exception
        public AgeTooOldException() { super(); }
        public AgeTooOldException(String message)
            super(message);
        public AgeTooOldException(String message, Throwable cause)
            super(message, cause);
        public AgeTooOldException(Throwable cause)
            super(cause);
        try
            String age = JOptionPane.showInputDialog("Please your age");
            int conAge = Integer.parseInt(age);
            if (conAge > 80) //if over 80 error - 80 is a "magic" number - terrible.
                throw new AgeTooOldException("Age is too old, must be less then 120");
        catch (AgeTooOldException ato)
            JOptionPane.showMessageDialog(ato.getMessage(), JOptionPane.ERROR_MESSAGE);
        catch (Exception e)
            JOptionPane.showMessageDialog(e.getMessage(), JOptionPane.ERROR_MESSAGE);

  • Java101: Catching and Handling Exceptions question

    Dear all,
    I am learning java from http://java.sun.com/docs/books/tutorial/essential/exceptions/putItTogether.html
    However, I think the code in ListOfNumbers may have some problem, I put void in front of the function, but still have error. Could you please tell me any problem in the program?
    thanks
    import java.util.Vector;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.*;
    public class Main {
        private Vector vector;
        private int SIZE = 10;
        public static void main(String[] args) throws IOException {
        public ListOfNumbers () {
            vector = new Vector(SIZE);
            for (int i = 0; i < SIZE; i++) {
                vector.addElement(new Integer(i));
        public void writeList() {
            PrintWriter out = new PrintWriter(
                                new FileWriter("OutFile.txt"));
            for (int i = 0; i < SIZE; i++) {
                out.println("Value at: " + i + " = " +
                             vector.elementAt(i));
            out.close();
            FileInputStream in = null;
            FileOutputStream out = null;
                in = new FileInputStream("xanadu.txt");
                out = new FileOutputStream("outagain.txt");
                int c;
                while ((c = in.read()) != -1) {
                    out.write(c);
        public void writeList() {
        PrintWriter out = null;
        try {
            System.out.println("Entering try statement");
            out = new PrintWriter(
                           new FileWriter("OutFile.txt"));
                for (int i = 0; i < 5; i++)
                    out.println("Value at: " + i + " = "
                                 + vector.elementAt(i));
        } catch (ArrayIndexOutOfBoundsException e) {
             System.err.println("Caught "
                         + "ArrayIndexOutOfBoundsException: "
                         +   e.getMessage());
        } catch (IOException e) {
             System.err.println("Caught IOException: "
                                 +  e.getMessage());
        } finally {
             if (out != null) {
                 System.out.println("Closing PrintWriter");
                 out.close();
             else {
                 System.out.println("PrintWriter not open");
    }

    I have also post the error message here, I change the name of the file and the class name. I think I can not handle the error message #1 and #2. Please help me! Thanks
    * Main.java
    * Created on June 19, 2007, 10:54 AM
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package bytestreams01;
    * @author Marco
    import java.util.Vector;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.*;
    public class Main {
        private Vector vector;
        private int SIZE = 10;
        public static void ListOfNumbers(String[] args) throws IOException {
        public ListOfNumbers () {
            vector = new Vector(SIZE);
            for (int i = 0; i < SIZE; i++) {
                vector.addElement(new Integer(i));
            FileInputStream in = null;
            FileOutputStream out = null;
                in = new FileInputStream("xanadu.txt");
                out = new FileOutputStream("outagain.txt");
                int c;
                while ((c = in.read()) != -1) {
                    out.write(c);
        public void writeList() {
        PrintWriter out = null;
        try {
            System.out.println("Entering try statement");
            out = new PrintWriter(
                           new FileWriter("OutFile.txt"));
                for (int i = 0; i < 5; i++)
                    out.println("Value at: " + i + " = "
                                 + vector.elementAt(i));
        } catch (ArrayIndexOutOfBoundsException e) {
             System.err.println("Caught "
                         + "ArrayIndexOutOfBoundsException: "
                         +   e.getMessage());
        } catch (IOException e) {
             System.err.println("Caught IOException: "
                                 +  e.getMessage());
        } finally {
             if (out != null) {
                 System.out.println("Closing PrintWriter");
                 out.close();
             else {
                 System.out.println("PrintWriter not open");
    }error message
    init:
    deps-jar:
    Compiling 1 source file to C:\Users\Marco\bytestreams01\build\classes
    C:\Users\Marco\bytestreams01\src\bytestreams01\ListOfNumbers.java:29: illegal start of expression
    public ListOfNumbers () {
    C:\Users\Marco\bytestreams01\src\bytestreams01\ListOfNumbers.java:29: invalid method declaration; return type required
    public ListOfNumbers () {
    C:\Users\Marco\bytestreams01\src\bytestreams01\ListOfNumbers.java:41: <identifier> expected
    in = new FileInputStream("xanadu.txt");
    C:\Users\Marco\bytestreams01\src\bytestreams01\ListOfNumbers.java:42: <identifier> expected
    out = new FileOutputStream("outagain.txt");
    C:\Users\Marco\bytestreams01\src\bytestreams01\ListOfNumbers.java:45: illegal start of type
    while ((c = in.read()) != -1) {
    C:\Users\Marco\bytestreams01\src\bytestreams01\ListOfNumbers.java:45: <identifier> expected
    while ((c = in.read()) != -1) {
    C:\Users\Marco\bytestreams01\src\bytestreams01\ListOfNumbers.java:45: ';' expected
    while ((c = in.read()) != -1) {
    C:\Users\Marco\bytestreams01\src\bytestreams01\ListOfNumbers.java:50: class, interface, or enum expected
    public void writeList() {
    C:\Users\Marco\bytestreams01\src\bytestreams01\ListOfNumbers.java:53: class, interface, or enum expected
    try {
    C:\Users\Marco\bytestreams01\src\bytestreams01\ListOfNumbers.java:55: class, interface, or enum expected
    out = new PrintWriter(
    C:\Users\Marco\bytestreams01\src\bytestreams01\ListOfNumbers.java:57: class, interface, or enum expected
    for (int i = 0; i < 5; i++)
    C:\Users\Marco\bytestreams01\src\bytestreams01\ListOfNumbers.java:57: class, interface, or enum expected
    for (int i = 0; i < 5; i++)
    C:\Users\Marco\bytestreams01\src\bytestreams01\ListOfNumbers.java:57: class, interface, or enum expected
    for (int i = 0; i < 5; i++)
    C:\Users\Marco\bytestreams01\src\bytestreams01\ListOfNumbers.java:61: class, interface, or enum expected
    } catch (ArrayIndexOutOfBoundsException e) {
    C:\Users\Marco\bytestreams01\src\bytestreams01\ListOfNumbers.java:66: class, interface, or enum expected
    } catch (IOException e) {
    C:\Users\Marco\bytestreams01\src\bytestreams01\ListOfNumbers.java:70: class, interface, or enum expected
    } finally {
    C:\Users\Marco\bytestreams01\src\bytestreams01\ListOfNumbers.java:73: class, interface, or enum expected
    out.close();
    C:\Users\Marco\bytestreams01\src\bytestreams01\ListOfNumbers.java:75: class, interface, or enum expected
    C:\Users\Marco\bytestreams01\src\bytestreams01\ListOfNumbers.java:78: class, interface, or enum expected
    19 errors
    BUILD FAILED (total time: 0 seconds)

  • Exceptions question

    I've written/modified the following code for a school assignment but have a small(i hope) question.
    Where i print the stack trace- i dont want to print the location of it- just that it was an illegal entry into the code(by user)
    my code>>
    // Factorials.java
    // Reads integers from the user and prints the factorial of each.
       import java.util.Scanner;
        public class Factorials
           public static void main(String[] args)
             String keepGoing = "y";
             Scanner scan = new Scanner(System.in);
             while (keepGoing.equals("y") || keepGoing.equals("Y"))
                System.out.print("Enter an integer: ");
                int val = scan.nextInt();
                try
                   System.out.println("Factorial(" + val + ") = "
                      + MathUtils.factorial(val));
                    catch(IllegalArgumentException problem)
                      problem.printStackTrace();
                System.out.print("Another factorial? (y/n) ");
                keepGoing = scan.next();
    // MathUtils.java
    // Provides static mathematical utility functions.
        public class MathUtils
        // Returns the factorial of the argument given
           public static int factorial(int n) throws IllegalArgumentException
             IllegalArgumentException problem =
                new IllegalArgumentException("Factorial function is not defined for negative integers");
             if(n<0)
                throw problem;
             int fac = 1;
             for (int i=n; i>0; i--)
                fac *= i;
             return fac;
       }The output i get at this point is as follows
    ----jGRASP exec: java Factorials
    Enter an integer: 5
    Factorial(5) = 120
    Another factorial? (y/n) y
    Enter an integer: -1
    java.lang.IllegalArgumentException: Factorial function is not defined for negative integers
         at MathUtils.factorial(MathUtils.java:17)
         at Factorials.main(Factorials.java:22)
    Another factorial? (y/n) n
    ----jGRASP: operation complete.
    and i'd like for it to be like this>>
    ----jGRASP exec: java Factorials
    Enter an integer: 5
    Factorial(5) = 120
    Another factorial? (y/n) y
    Enter an integer: -1
    java.lang.IllegalArgumentException: Factorial function is not defined for negative integers
    Another factorial? (y/n) n
    ----jGRASP: operation complete.
    Any hint, help, or suggestion would be greatly appreciated :D

    Instead of problem.printStackTrace(); useSystem.out.println(problem.getMessage());
    The problem now is that it only prints the created problem message-
    as my assignment shows its supposed to print
    java.lang.IllegalArgumentException: Factorial function is not defined for negative integers
    but with no at... at... the locations of the exception

  • Some basic questions how to handle Exceptions with good style

    Ok I have two really basic Exception questions at once:
    1. Until now I always threw all exceptions back all the way to my main method and it always worked well for me but now I am sitting at a big project where this method would explode the programm with throwings of very many exceptions in very many methods. So I would like to know if there is a more elegant solution.
    2. What do I do with exceptions that will never occur?
    Lets say I have a method like this:
    void main() {calculate();}
    void calculate()
    sum(3,5);
    void sum(int a,int b)
    MathematicsA.initialise("SUM"); // throws AlgorithmNotFoundException, will never occur but has to be handled
    }So what is the most elegant way?:
    h4. 1. Ignore because it will not happen
    void sum(int a,int b)
    try {MathematicsA.initialise("SUM");}
    catch(AlgorithmNotFoundException) {}
    }h4. 2. Print stacktrace and exit
    void sum(int a,int b)
    try {MathematicsA.initialise("SUM");}
    catch(AlgorithmNotFoundException e)
    e.printStackTrace();
    System.exit();
    }h4. 3. throw it everywhere
    void main() throws AlgorithmNotFoundException, throws ThousandsOfOtherExceptions  {}
    void calculate()  throws AlgorithmNotFoundException, throws HundretsOfOtherExceptions
    sum(3,5);
    void sum(int a,int b) throws AlgorithmNotFoundException
    MathematicsA.initialise("SUM");
    }h4. 4. Create special exceptions for every stage
    void main() throws MainParametersWrongException
    try {calculate();}
    catch(Exception e)
      throw new MainParametersWrongException();
    void calculate()  throws SumInternalErrorException
    try {sum(3,5);}
    catch (SumInternalErrorException)    {throw new CalculateException();}
    void sum(int a,int b) throws SumInternalErrorException
    try
    MathematicsA.initialise("SUM");
    } catch (AlgorithmNotFoundException e) {
    throw new SumInternalErrorException();
    }P.S.: Another problem for me is when a method called in a constructor causes an Exception. I don't want to do try/catch everytime I instantiate an object..
    Example:
    public class MySummation()
         Mathematics mathematics;
         public MySummation()
                 mathematics.initialise("SUM"); // throws AlgorithmNotFoundException
         void sum(int x,int y)
              return mathematics.doIt(x,y);
    }(sorry for editing all the time, I was not really sure what I really wanted to ask until i realised that I had in fact 2 questions at the same time, and still it is hard to explain what I really want to say with it but now the post is relatively final and I will only add small things)
    Edited by: kirdie on Jul 7, 2008 2:21 AM
    Edited by: kirdie on Jul 7, 2008 2:25 AM
    Edited by: kirdie on Jul 7, 2008 2:33 AM
    Edited by: kirdie on Jul 7, 2008 2:34 AM

    sphinks wrote:
    I`m not a guru, but give my point of view. First of all, the first way is rude. You shouldn`t use try with empty catch. "rude" isn't the word I'd use to describe it. Think about what happens if an exception is thrown. How will you know? Your app fails, and you have NO indication as to why. "stupid" or "suicidal" are better descriptions.
    Then for the second way, I`ll reccomend for you use not printStackTrace(); , but use special method for it:
    public void outputError (Exception e) {
    e.printStackTrace();
    }It`ll be better just because if in future you`d like to output error message instead of stack of print it on GUI, you`ll need change only one method, but not all 'try' 'catch' statements for changing e.printStackTrace(); with the call of new output method.I disagree with this. Far be it from me to argue against the DRY principle, but I wouldn't code it this way.
    I would not recommend exiting from a catch block like that. It's not a strategy for recovery. Just throw the exception.
    Then, the third way also good, but I suppose you should use throws only if the caller method should know that called method have a problem (for example, when you read parametrs from gui, so if params are inccorect, main method of programm should know about it and for example show alert window)."throw it everywhere"? No, throw it until you get to an appropriate handler.
    If you're writing layered applications - and you should be - you want to identify the layer that will handle the exception. For example, if I'm writing a web app with a view layer, a service layer, and a persistence layer, and there's a problem in the persistence tier, I'd let the service layer know what the persistence exception was. The service layer might translate that into some other exception with some business meaning. The view layer would translate the business exception into something that would be actionable by the user.
    And in all other cases I suppose you should use the fourth way. So I suppose it`s better to combine 2,3,4 ways as I have mentioned above.I don't know that I'd recommend special exceptions for every layer. I'd reuse existing classes where I could (e.g., IllegalArgumentException)
    Sorry, I can give you advice how to avoid problem with try-catch in constructor. :-(You shouldn't catch anything that you can't handle. If an exception occurs in a constructor that will compromise the object you're trying to create, by all means just throw the exception. No try/catch needed.
    You sound like you're looking for a single cookie cutter approach. I'd recommend thinking instead.
    %

  • Exception doubts (urgent)

    Question no 1 :
    Given:
    boolean bool = true;
    if(bool = false) {
    System.out.println("a");
    } else if (bool) {
    System.out.println("c");
    } else if (!bool) {
    System.out.println("c");
    } else {
    System.out.println("d");
    What is the result?
    A. a
    B. b
    C. c
    D. d
    E. Compilation fails.
    Question no 2:
    class Super {
    public int i = 0;
    public Super(String text) {
    i = 1;
    public class Sub extends Super {
    public Sub(String text) {
    i = 2;
    public static void main(String args[]) {
    Sub sub = new Sub("Hello");
    System.out.println(sub.i);
    What is the result?
    A. 0
    B. 1
    C. 2
    D. Compilation fails.
    Question no 3 :
    Given:
    try {
    int x = 0;
    int y = 5 / x;
    } catch (Exception e) {
    System.out.println("Exception");
    } catch (ArithmeticException ae) {
    System.out.println("Arithmetic Exception");
    System.out.println("finished");
    What is the result?
    A. finished
    B. Exception
    C. Compilation fails.
    D. Arithmetic Exception
    Question no 4 :
    public class SyncTest{
    public static void main(String[] args) {
    final StringBuffer s1= new StringBuffer();
    final StringBuffer s2= new StringBuffer();
    new Thread () {
    public void run() {
    synchronized(s1) {
    s2.append("A");
    synchronized(s2) {
    s2.append("B");
    System.out.print(s1);
    System.out.print(s2);
    }.start();
    new Thread() {
    public void run() {
    synchronized(s2) {
    s2.append("C");
    synchronized(s1) {
    s1.append("D");
    System.out.print(s2);
    System.out.print(s1);
    }.start();
    Which two statements are true? (Choose Two)
    A. The program prints "ABBCAD"
    B. The program prints "CDDACB"
    C. The program prints "ADCBADBC"
    D. The output is a non-deterministic point because of a possible deadlock condition.
    E. The output is dependent on the threading model of the system the program is
    running on.

    Bloody cross-poster
    http://forum.java.sun.com/thread.jspa?threadID=639843
    Do your homework yourself.

  • User Not Found When Attempting to Sign In To FusionHQ

    Hello Firefox Tech Support,
    When I initialized Firefox in order to sign into my Fusionhq software, first, there was the Prompt from Firefox inquiring as to whether I can trust the Fusionhq site. Then, after responding Yes, I can vaguely recall some things about my signing in being an Exception in this case, and I believe that I responded Yes, when I should have responded No, wherein I was taken back to the Fusionhq Sign-In Screen. Upon attempting to sign in at the new Fusionhq Sign-In Screen, I then got the “User Not Found” message. For good measure, there might have been an additional Prompt before I got to the Exception Question.
    Can you please have my original sign in reset, in order that I can go back to Firefox to sign into Fusionhq anew ? Once done, I can go back through the sign in process and then follow a different route for the Prompts.
    Thanks.
    John

    My problem is now resolved.
    Thanks.

  • Calculator 's functions. Difficult. need some help.

    I did do for my own calculator,but i got problem with animation and sound for the calculator. Like :
    Pressing a wrong combination of keys may generate a warning sound. Moreover an animated icon
    should be used to indicate when:
    + the calculator is idle and free to be used
    + the calculator is busy ( being used )
    This is my own program, anybody can show me how to add the warning sound and animation icon according above requirement ???? Or any online tutorial about this one. This program is working on the right way, but i don't know how to add some more feature like animation icon, and warning sound.Pleaseeeeeeeeeeeee help me, it is urgent.
    import java.awt.event.*;
    import java.awt.*;
    public class Calculator extends Frame implements ActionListener
    TextField name;
    Label aHeader;
    Button b[];
    String expression;
    // Calculator Constructor
    // This operator constructor ( as with all constructors ) is executed when the new object
    // is created. In this case we create all the buttons ( and the panels that contain them )
    // then reset the calculator
    public Calculator()
    super("DUY 'S CALCULATOR");     
    setLayout(new BorderLayout());     
    Panel p1 = new Panel();
    p1.setBackground(new Color(18,70,1));
    p1.setLayout(new FlowLayout());
    aHeader = new Label("DUY'S CALCULATOR");
    aHeader.setFont(new Font("Times New Roman",Font.BOLD,24));
    aHeader.setForeground(new Color(255,0,0));
    p1.add(aHeader);
    // Question: what does 'North' mean here ?
    // The applet places a GridLayout on the 'North' side
    add("North",p1);
    Panel p2 = new Panel();
    p2.setBackground(new Color(27,183,100));
    p2.setLayout(new GridLayout(0,1));
    // When you create p2 GridLayout you specify 'new GridLayout(0,1) 'which means create a new GridLayout with 1 column .( no row)
    name = new TextField(20); // Var for Text field max of 20 characters
    p2.add(name);
    add("Center",p2);
    Panel p3 = new Panel();
    p3.setLayout(new GridLayout(0,6));
    // When you create p3 GridLayout you specify 'new GridLayout(0,1) 'which means create a new GridLayout with 6 columns .( no row)
    b = new Button[25];
    b[0] = new Button("MC");     // Create Button MC
    b[0].addActionListener(this);
    b[1] = new Button("7");     // Create Button Seven
    b[1].addActionListener(this);
    b[2] = new Button("8");     // Create Button Eight
    b[2].addActionListener(this);
    b[3] = new Button("9");     // Create Button Nine
    b[3].addActionListener(this);
    b[4] = new Button("/");     // Create Button Div
    b[4].addActionListener(this);
    b[5] = new Button("sqrt");     // Create Button SQRT
    b[5].addActionListener(this);
    b[6] = new Button("CE");     // Create Button CE
    b[6].addActionListener(this);
    b[7] = new Button("4");     // Create Button Four
    b[7].addActionListener(this);
    b[8] = new Button("5");     // Create Button Five     
    b[8].addActionListener(this);
    b[9] = new Button("6");     // Create Button Six
    b[9].addActionListener(this);
    b[10] = new Button("*");     // Create Button Multi
    b[10].addActionListener(this);
    b[11] = new Button("%");     // Create Button Percent
    b[11].addActionListener(this);
    b[12] = new Button("MS");     // Create Button MS
    b[12].addActionListener(this);
    b[13] = new Button("1");     // Create Button One
    b[13].addActionListener(this);
    b[14] = new Button("2");     // Create Button Two
    b[14].addActionListener(this);
    b[15] = new Button("3");     // Create Button Three
    b[15].addActionListener(this);
    b[16] = new Button("-");     // Create Button Minus
    b[16].addActionListener(this);
    b[17] = new Button("1/x");     // Create Button Calculates the multiplicative inverse
    b[17].addActionListener(this);
    b[18] = new Button("M+");     // Create Button M+
    b[18].addActionListener(this);
    b[19] = new Button("0");     // Create Button Zero     
    b[19].addActionListener(this);
    b[20] = new Button("+/-");     // Create Button +/-
    b[20].addActionListener(this);
    b[21] = new Button(".");     // Create Button point
    b[21].addActionListener(this);
    b[22] = new Button("+");     // Create Button Plus
    b[22].addActionListener(this);
    b[23] = new Button("=");     // Create Button Equal     
    b[23].addActionListener(this);
    b[24] =new Button("exit");     // Create Button Exit
    b[24].addActionListener(this);
    // clearAll sets the attributes of the Calculator object to initial values ( this is
    // the operation that is called when the user click on the "CE" button.
    for(int i=0;i<=24;i++)
    {      p3.add(b[i]);
    add("South",p3);
    // Question : what does 'South' mean here ? The applet places a GridLayout on the
    // 'South' side
    super.addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent e)
    {System.exit(0);}});
    // Window Closing
    // This operation is called in response to a window closing event. It should simply
    // exit the program
    setLocation(200,100);
    pack();
    setVisible(true);
    // End of constructor
    //* actionPerformed:: This operation is call whenever the user click a button .All
    // this operation does is pass on the text on the button to ' evt '
    public void actionPerformed(ActionEvent evt)
    String command = evt.getActionCommand();
    StringBuffer tmp, first, second;
    int value, size, k;
    char ch, op = ' ';
    first = new StringBuffer();
    second = new StringBuffer();
    //* processButton:This operation takes action according to the user's input. It is called
    // from two other operation :actionPerformed ( when user click a button ) andkeypressed
    // ( when user press a key on the keyboard ). This operation examines the text on the button
    // by ( the parameter 'command') and calls the appropriate operation to process it
    if ("CE".equals(command))
    name.setText("");
    else if("7".equals(command))
    expression = name.getText();
    name.setText(expression+"7");
    else if ("8".equals(command))
    expression = name.getText();
    name.setText(expression+"8");
    else if ("9".equals(command))
    expression = name.getText();
    name.setText(expression+"9");
    else if("4".equals(command))
    expression = name.getText();
    name.setText(expression+"4");
    else if("5".equals(command))
    expression = name.getText();
    name.setText(expression+"5");
    else if("6".equals(command))
    expression = name.getText();
    name.setText(expression+"6");
    else if("1".equals(command))
    expression = name.getText();
    name.setText(expression+"1");
    else if("2".equals(command))
    expression = name.getText();
    name.setText(expression+"2");
    else if("3".equals(command))
    expression = name.getText();
    name.setText(expression+"3");
    else if("0".equals(command))
    expression = name.getText();
    name.setText(expression+"0");
    else if("+".equals(command))
    expression = name.getText();
    name.setText(expression+"+");
    else if("-".equals(command))
    expression = name.getText();
    name.setText(expression+"-");
    else if("*".equals(command))
    expression = name.getText();
    name.setText(expression+"*");
    else if("/".equals(command))
    expression = name.getText();
    name.setText(expression+"/");
    //processEquals : Deal with the user clicking the '=' button. This operation finishes
    // the most recent calculator
    else if("=".equals(command))
    expression = name.getText();
    size = expression.length();
    tmp = new StringBuffer( expression );
    for(int i = 0;i<size;i++)
    ch = tmp.charAt(i);
    if(ch != '+' && ch != '*' && ch != '-' && ch != '/')
    first . insert(i, ch);
    else
    op = ch;
    k = 0;
    for(int j = i+1; j< size ; j++)
    ch = tmp.charAt(j);
    second.insert(k,ch);
    k++;
    break;
    switch(op)
    //* processLastOperator : Carries out the arithmetic operation specified by the last
    // operator, the last number and the number in the display.If the operator causes an
    // error condition ( ex : the user tries to devide something by zero), this operation an
    // exception     
    // Question : if the user click on the button '2' , '+', '3' what values will found ?
    case '+' : value = Integer.parseInt(new String(first)) +
    Integer.parseInt(new String(second));
    name.setText(new Integer(value).toString());
    break;      // plus button
    case '-' : value = Integer.parseInt(new String(first)) -
    Integer.parseInt(new String(second));
    name.setText(new Integer(value).toString());
    break;
    case '*' : value = Integer.parseInt(new String(first)) *
    Integer.parseInt(new String(second));
    name.setText(new Integer(value).toString());
    break;
    case '/' : value = Integer.parseInt(new String(first)) /
    Integer.parseInt(new String(second));
    name.setText(new Integer(value).toString());
    break;
    } //end of actionPerformed
    /**main method to invoke from JVM.*/
    public static void main(String args[])
    new Calculator(); // Create a new instance of the Calculator object

    Here's your code fixed up the enw way. It works the same, except it is half the size
    package jExplorer;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    public class Calculator extends Frame implements ActionListener
      final static String[] bNames = {"7", "8", "9", "/", "sqrt", "CE", "4", "5", "6", "*", "%", "MS", "1", "2", "3", "-", "1/x", "M+", "0", "+/-", ".", "+", "=", "exit"};
      final static int NUM_BUTTONS = bNames.length;
      private TextField name;
    * Calculator Constructor
    * This operator constructor ( as with all constructors ) is executed when the new object
    * is created. In this case we create all the buttons ( and the panels that contain them )
    * then reset the calculator
      public Calculator()
        super( "DUSTPANTS CALCULATOR" );
        setLayout( new BorderLayout() );
        Panel p1 = new Panel();
        p1.setBackground( new Color( 18, 70, 1 ) );
        p1.setLayout( new FlowLayout() );
        Label aHeader;
        aHeader = new Label( "DUSTPANTS CALCULATOR" );
        aHeader.setFont( new Font( "Times New Roman", Font.BOLD, 24 ) );
        aHeader.setForeground( new Color( 255, 0, 0 ) );
        p1.add( aHeader );
    // Question: what does 'North' mean here ?
    // The applet places a GridLayout on the 'North' side
        add( "North", p1 );
        Panel p2 = new Panel();
        p2.setBackground( new Color( 27, 183, 100 ) );
        p2.setLayout( new GridLayout( 0, 1 ) );
        name = new TextField( 20 ); // Var for Text field max of 20 characters
        p2.add( name );
        add( "Center", p2 );
        Panel p3 = new Panel();
        p3.setLayout( new GridLayout( 0, 6 ) );
    // Create buttons & their ActionListeners, and add them to the panel
        Button b[];
        b = new Button[NUM_BUTTONS];
        for( int x = 0; x < NUM_BUTTONS; x++ )
          b[x] = new Button( bNames[x] );
          b[x].addActionListener( this );
          p3.add( b[x] );
        add( "South", p3 );
        super.addWindowListener( new WindowAdapter()
          public void windowClosing( WindowEvent e )
            System.exit( 0 );
        setLocation( 200, 100 );
        pack();
        setVisible( true );
    * actionPerformed:: This operation is call whenever the user click a button .All
    * this operation does is pass on the text on the button to ' evt '
      public void actionPerformed( ActionEvent evt )
        String command = evt.getActionCommand();
        String expression;
        int value, size, k;
        char ch, op = ' ';
        StringBuffer tmp;
        StringBuffer first = new StringBuffer();
        StringBuffer second = new StringBuffer();
        if( "CE".equals( command ) )
          name.setText( "" );
        else if( "=".equals( command ) )
          expression = name.getText();
          tmp = new StringBuffer( expression );
          size = tmp.length();
          for( int i = 0; i < size; i++ )
            ch = tmp.charAt( i );
            if( ch != '+' && ch != '*' && ch != '-' && ch != '/' )
            { first.insert( i, ch ); }
            else
              op = ch;
              k = 0;
              for( int j = i + 1; j < size; j++ )
                ch = tmp.charAt( j );
                second.insert( k, ch );
                k++;
              break;
        else if( validButton( command ) )
          expression = name.getText();
          name.setText( expression + command );
        else
          Toolkit.getDefaultToolkit().beep();
       * processLastOperator : Carries out the arithmetic operation specified by the last
       * operator, the last number and the number in the display.If the operator causes an
       * error condition ( ex : the user tries to devide something by zero), this operation an
       * exception
       * Question : if the user click on the button '2' , '+', '3' what values will found ?
        switch( op )
          case '+':
            value = Integer.parseInt( new String( first ) ) +
              Integer.parseInt( new String( second ) );
            name.setText( new Integer( value ).toString() );
            break; // plus button
          case '-':
            value = Integer.parseInt( new String( first ) ) -
              Integer.parseInt( new String( second ) );
            name.setText( new Integer( value ).toString() );
            break;
          case '*':
            value = Integer.parseInt( new String( first ) ) *
              Integer.parseInt( new String( second ) );
            name.setText( new Integer( value ).toString() );
            break;
          case '/':
            value = Integer.parseInt( new String( first ) ) /
              Integer.parseInt( new String( second ) );
            name.setText( new Integer( value ).toString() );
            break;
      private static final boolean validButton( String command )
        for( int x = 0; x < NUM_BUTTONS; x++ )
          if( bNames[x].equals( command ) ) ;
            return true;
        return false;
      /** main method to invoke from JVM. */
      public static void main( String args[] )
        new Calculator(); // Create a new instance of the Calculator object
    }

  • Opening Captivate 2 Project in Version 3...Error

    I apologize if this issue has already been raised; however,
    I'm getting an
    error when opening a CP2 file in CP3. This was originally a
    version 1
    project, which was opened in version two for some minor
    changes. I need to
    make two minor tweaks and can't. The file size is
    approximately 9 MB.
    Allows me to overwrite or save as a different file name. I
    have tried both.
    A message appears: "Exception Occored" followed by "Adobe
    Captivate could
    not open "filename.cp" because it is either not a supported
    file type or
    because the file has been damaged..."
    I can open the file in version 2 without difficulty. I want
    to use version 3
    because I heard that the final .swf file will be smaller
    (also, I don't want
    to continue using 2 for some projects and 3 for others).
    Any clue as to what is going on and how I can get the file
    into version 3?
    Thanks!

    Thanks! This worked for me. Another question...the size of
    the cp file is
    500KB larger, but the compiled version is slightly smaller.
    It looks as
    though some of the images in the library were duplicated to
    be used for
    different backgrounds. Has anyone tried inserting the
    original background
    and deleting the duplicate? Has it caused problems?
    Thanks!
    "CatBandit" <[email protected]> wrote in
    message
    news:[email protected]...
    > Hi Brian,
    > I think what might be happening is that Captivate 3 is
    still reading your
    > file
    > as a version 1 project. And while CP3 can open CP
    projects, I'm not so
    > sure it
    > will accept the jump from two versions earlier. Just a
    thought.
    >
    > But that doesn't solve your problem, so if I am right
    about the above and
    > there is a chance I am not), the trick is to make
    Captivate 3 "think" that
    > it's
    > a version 2 file, and see if that helps. Since you still
    have version 2,
    > that
    > trick might be possible (no promises).
    >
    > 1) Try opening a new project (blank) of the same size in
    Captivate 3.
    > 2) Then open the target project in Captivate 2.
    > 3) With both open, just cut-and-paste the slides from
    ver2 to ver3.
    >
    > I'm thinking it should work for two reasons. First,
    there are no objects
    > in
    > Captivate 2 that are not supported in Captivate 3
    (except Question slides
    > are
    > treated differently and if you have them, you may be
    sunk).
    >
    > Second, if you just cut-and-paste, Windows clipboard
    doesn't know or care
    > which product, much less which version. All it sees is
    "objects", and it
    > should copy the slide and all contents without problem,
    so long as all
    > objects
    > are "accepted" by the receiving application (Captivate
    version 3).
    >
    > Hope this makes sense, and works for you. There are
    reasons why you may
    > not
    > be able to use this (system resources if the file is too
    large, for
    > instance,
    > as well as the issue just covered above). But if it
    works, it might save
    > you
    > having multiple product versions cluttering up your hard
    drive.
    >
    > Best of luck, and keep in touch with an update on your
    results if you
    > would.
    > Thanks!
    > .
    >

  • Need help. I am running a 27 in imac with 16 gigs of ram. Photoshop runs really fast, except when opening files. It takes 5-10 minutes to open even a small file of 1 meg. I cleaned and validated all the fonts and removed all questionable fonts. Reset pref

    Need help. I am running a 27 in imac with 16 gigs of ram. Photoshop runs really fast, except when opening files. It takes 5-10 minutes to open even a small file of 1 meg. I cleaned and validated all the fonts and removed all questionable fonts. Reset preferences and still have problem. Slow to open and in force quit "Photoshop not responding" At this point should I uninstall and start over.

    What are the performance Preferences?

  • How to get a question in the course placed anywhere in the course and does not appear in the quiz result or total number of questions. Pretest would work except it can't go anywhere in the course (at least for me it can't)

    How to get a question in the course placed anywhere in the course and does not appear in the quiz result or total number of questions. Pretest would work except it can't go anywhere in the course (at least for me it can't)

    Use a normal question, and do not add the score to the total score. That will give you a correct score at the end. But the total number of questions, that system variable will still take into account all questions. You'll need a user variable, and calculate its value by subtracting 1 from the system variable cpQuizInfoTotalQuestionsPerProject. Same for the progress indicator if you want to show it?
    Customized Progress Indicator - Captivate blog
    If you want to allow Review, you'll have to tweak as well. You didn't specify the version, and all those questions I now mentioned.
    And my approach, since you talk about only one question: create a custom question, because you'll have total control then.

  • Exception Processing Question -Reply

    I don't use Forte (yet--that's why I joined the mailing list), but since your
    question is a generic "engineering practices" question, I'll chime in. I do
    use exceptions both in C++ in Delphi, and have developed some opinions
    about how to use them:
    - Use exceptions for handling "behavior unexpected in the normal course
    of your algorithm". In other words, instead of returning error codes
    when something goes wrong, throw an exception.
    One example of this is in a parser: if you get an illegal token, just throw
    an exception.
    - When you need to make a choice based on a return status, don't throw
    an exception. In the parser example, if you get token 'A', you need to do
    one thing and if you get token 'B' you need to do another.
    - There's a fine distinction between "handling an error" and "making a
    choice", and there are cases where you could argue one way or the
    other. I'd say that an error throws an exception when it would normally
    terminate the normal flow of execution. For example, "out of memory" or
    "illegal token".
    - Catch exceptions at "high level" process start/end points, or where it is
    required to clean up resources held and rethrow.
    - Don't catch exceptions in every single method--it defeats the purpose.
    User Interfaces:
    - If your user-interface dictates a logical place to unwind no further,
    catch exceptions there. For example: In the Windows world most apps
    are a window with a menu. If you pull down and pick a menu item to
    execute a command, and that command throws an exception, the
    exception should be caught, a modal message box indicating the error
    should be presented, and then when the user clicks "ok", the program
    returns to its normal waiting state with the window intact.
    - If you have a modal dialog up, throwing an exception should either stop
    at the dialog's event loop or take the dialog down with it.
    I'd say that on-screen data validation should NOT use exceptions
    because "user typing invalid data" is expected behavior for a UI.
    Besides, the UI designer should be smart enough to deal with giving you
    a good model for data validation. OTOH, if you take the data out of the
    dialog and then pass the information as parameters to a function, and
    that function can't handle one of the parameter values, it should throw an
    exception.
    Nevertheless, if your dialog runs out of memory for some reason, it
    should throw an exception and the dialog should come down.
    Hope this helps.
    -- Conrad Herrmann
    Jerry Fatcheric <[email protected]> 07/24/96 03:29am >>>
    I have a toss up question for 50 points -
    We have finished the first phase of our project and have place
    exception processing in the places where we saw exceptions could be
    raise. But what about those other exceptional exceptions?
    Is this just good programming practice to have a high level generic
    exception handler (and what should it really do??) or is it critical.
    In addition, when handling data validation on specific widgets on a
    screen (e.g. the account number entered must be one of the existing
    10,000 valid ones), should this be handled via exception processing or
    should it just be handled with code in the event loop?
    Any opinions - please I don't want to hear the Forte Party line.
    I would like to hear opinions based upon real experience.
    Jerry Fatcheric
    Relational Options, Inc.
    Florham Park, New Jersey
    201-301-0200
    201-301-00377 (FAX) [email protected]

    We have finished the first phase of our project and have place
    exception processing in the places where we saw exceptions could
    be raise. But what about those other exceptional exceptions?
    Is this just good programming practice to have a high level
    generic exception handler (and what should it really do??) or
    is it critical.IMHO, you need to program for these ones that could occur because
    if you don't the exception will still happen except without
    your normal graceful (or standard) approach manner. I think it is good programming
    practice to trap on the ones you think can possible occur if they require
    something different in how they react. Otherwise, use of GenericException
    with a proper response is called for.
    >
    In addition, when handling data validation on specific widgets
    on a screen (e.g. the account number entered must be one of the
    existing 10,000 valid ones), should this be handled via exception
    processing or should it just be handled with code in the event loop?
    I use event loop processing because most of the time I am also
    keeping the user on the same widget after cancelling all events
    posted. So, in effect they are back where they started from.
    Any opinions - please I don't want to hear the Forte Party line.
    I would like to hear opinions based upon real experience.
    Jerry Fatcheric
    [email protected]@Sagesoln.com
    my 2 cents, or should I say my attempt at 50 points, Jerry.
    Len Leber
    ATG Partners

Maybe you are looking for