Exception OrderException is never thrown in body of corresponding try state

Currently, I have a problem with a throwing an exception that I created. No matter what I try, it continues to give me this error. My code is below and I cannot figure out what I am doing wrong. Any suggestions??
public class OrderException extends Exception
     public OrderException(String s)
          super(s);
public class ExceptionOrder extends JFrame implements ActionListener
//my code creates items in JFrame
     public ExceptionOrder()
          //creates JFrame
     public class Order
          String itemNumber = new String();
          int itemNum;
     public Order(String itn, int itnum) throws OrderException
               itemNumber = itn;
               itemNum = itnum;
               //itemQuantity = itq;
               if((itnum <= 111) || (itnum >= 999)) throw(new OrderException(itn));
     public void actionPerformed(ActionEvent e)
          int numItem;
          int itemPrice;
          int itemQuantity;
          itemPrice = 1;
          try
          numItem = Integer.parseInt(item.getText());
          itemQuantity = Integer.parseInt(quantity.getText());
          itemPrice = itemQuantity * 2;
          price.setText(String.valueOf(itemPrice));
          catch(OrderException e2)
          //DOES NOT LIKE OrderException
          //says we did not throw OrderException in try statement
          //when run with a JAVA Exception, like NumberFormatException
          //program runs
               System.err.println("Invalid Item Number or Quantity");
               //itemPrice = itemQuantity * 2;
any thoughts/suggestions??

I'm not sure what you are asking. Can you please
eloborate? I have a class named Order that I am
trying to throw my exception if the itNum is <=111 or
=999. I'm not sure what you mean...
Throwing an exception is a property of a function or a constructor, not of a class. So if you don't use the constructor of the class Order in your try-statement no OrderException can be thrown.

Similar Messages

  • Netscape.javascript.JSException is never thrown in body of corresponding tr

    I have the following try/catch block:
    try
              netscape.javascript.JSObject.getWindow(this.applet).eval("ClkExcept(" + nId.toString() + ")");
            }catch(netscape.javascript.JSException e){}Which, for as long as I have compiled (until recently) compiled fine. However, when I recently had to recompile the classes containing this code because of an unrelated issue, I now get a message from the compiler stating that exception netscape.javascript.JSException is never thrown in body of corresponding try statement. I am attempting to use the latest 1.3.1_XX SDK (I must compile with some build of 1.3.1), but have run into this compiler message with all builds of 1.3.1 that I have tried. All documentation I can locate for the netscape.javascript.JSObject class states that the GetWindow() function can throw an exception of type netscape.javascript.JSException.
    Has anyone seen this before, or does anyone have any suggestions on how to get the compiler working correctly?

    This code has not been edited in two years, but has
    been recompiled numerous times since then (until
    today) without any compiler messages pertaining to
    this try/catch block. I know for a fact that the
    GetWindow() function can throw a JSException. Have you changed compilers recently?
    Have you tried compiling a brand new tiny test program in a different directory, with an explicit -classpath arg that contains only that relevant jar file, and no other classes in the directory?
    Have you tried extracting the class file from the jar, running it through a decompiler, and seeing what it says about the exception?
    If I
    remove the try/catch block and there is a problem
    with the javascript function that is called on the
    page hosting my applet there would obviously be an
    exception to catch. Removing the try/catch block is
    not a solution.You could try catching Exception instead. That will pass the compiler, because Exception includes RuntimeException and its descendants, and the compiler can't know that those won't be thrown, since they're unhecked. I'd consider that a last-ditch hack though, and wouldn't do it unless I'd thoroughly investigated first.

  • Exception not being thrown in try statement

    I am trying to write a small program to handle exceptions. However, the program will not compile because it is giving me an error saying the exception InvalidDocumentCodeException will never be thrown in body of coresponding try statement. Here are the two programs:
    public class InvalidDocumentCodeException extends Exception {
    InvalidDocumentCodeException (String message) {
    super(message);
    and
    import java.util.Scanner;
    public class Main2 {
    // Creates an exception object and possibly throws it.
    public static void main (String[] args) {
    char designation;
    String input = null;
    int valid = 0;
    Scanner scan = new Scanner (System.in);
    System.out.print ("Enter a 2-digit designation starting " + "\n" +
    "with U, C, or P, standing for unclassified, " + "\n" +
    "confidential, or proprietary: ");
    input = scan.nextLine();
    try {
    designation = input.charAt(0);
    if(designation == 'U')
    valid++;
    else if(designation == 'C')
    valid++;
    else if(designation == 'P')
    valid++;
    else if(designation == 'u')
    valid++;
    else if(designation == 'c')
    valid++;
    else if(designation == 'p')
    valid++;
    catch (InvalidDocumentCodeException problem) {
    System.out.println("Invalid designation entered " +
    problem);
    System.out.println ("End of main method.");
    can anyone tell me what I am doing wrong here?

    kenporic wrote:
    Forgive me, This is the first time I have used this sight and I should have been more precise. Thanks for all the help, but this is an excercise in how to handle exceptions in Java. One way is to "throw" the exception to another class to be handled. The other is to handle the exception within the running class. The throws program That I have works. The problem that I am having is handling the exception within the class without coding the "throws" statement. I am supposed to use the try-catch method in doing this. In the example I was given to follow, the code did not specifically throw the exception. If the input was not handled in the processing code then the catch statement is supposed to call to the exception class somehow?Okay, there are two families of exceptions--checked and unchecked.
    Checked: These are for things that are not part of the "happy path" of your code, but that your code may reasonably be expected to deal with. They're not necessarily signs of a bug in your code, nor do they indicate a problem in the JVM that's beyond your control. They're for things like when a file you're looking for doesn't exist (so maybe you handle it by asking the user to pick a different file), or a network connection being lost (so maybe you handle it by waiting a few seconds and trying again).
    When a checked exception occurs, since it's an expected and recoverable occurrence, you're expected to deal with it. So, when one of these exceptions can occur in your method, your method is required to either a) handle it (with catch) or b) let the caller know that HE might be asked to deal with it.
    We must either handle it:
    void doFileStuff(String path) {
      try {
        do file stuff
      catch (IOException exc) {
        retry--which means the whole try catch would be in a loop
        or maybe just substitute some default values that don't have to come from a file
    }Or let our caller know that he's going to have to handle it (or pass it on to his own caller):
    void doFileStuff(String path) throws IOException) {
      // this might throw an exception, but it's not this method's job to handle is, so it bubbles up to our caller
      do file stuff;
    Unchecked: These are things that are either bugs in your code (like a NullPointerException) or serious problems with the JVM that are beyond our control (like OutOfMemoryEror). These can occur anywhere, and it's not generally our code's job or our caller's job to deal with them, so they don't need to be caught or declared like checked exceptions do. You can catch them, and there are some places where it's appropriate to do so, but leave that aside for now.
    Unchecked exceptions are RuntimeException, Error, and every class that descends from them. Checked exceptions are everything else under Throwable, and Throwable itself.
    Now, when you do
    void foo() throws SomeException {You're telling the compiler that this method might throw that exception.\
    If SomeException is a checked exception, the compiler is able to tell whether your claim that you might throw it is true. Since it's checked, every method that might throw it must declare it. So the compiler can look at all the methods you call and see if they throw SomeException. If none of them do, and you don't explicitly put throw new SomeException(...); in your foo() method, then the compiler can be absolutely sure that there's no way foo() will throw SomeException. So it won't let you claim to throw it.
    On the other hand, is SomeException is unchecked, then since methods aren't required to report the unchecked exceptions they can throw, the compiler has no way of knowing whether some method you call might throw SomeException, so it always lets you declare it (and never requries you to).

  • Compile error: NoSuchMethodException never thrown

    I try to update my code from weblogic4.0 to weblogic5.1 and I recieve error: IMidtier_WLStub.java: Exception java.lang.NoSuchMethodException never thrown in the body corresponding try statement } catch{java.lang.NoSuchMethodException}. Could you help me to figure out why I start getting this method? Thank you. Vladimir.

    Can you show us the full error?
    If you're going to use WLS 5.1, ensure that you have the latest service pack installed as well. Also, double-check that it's installed correctly.
    I would strongly recommend that you go straight to WLS 6.1. It's a much better server, and it includes a much better EJB container.
    -- Rob
    Vladimir wrote:
    I try to update my code from weblogic4.0 to weblogic5.1 and I recieve error: IMidtier_WLStub.java: Exception java.lang.NoSuchMethodException never thrown in the body corresponding try statement } catch{java.lang.NoSuchMethodException}. Could you help me to figure out why I start getting this method? Thank you. Vladimir.

  • This exception is never thrown from the try statement body

    try {
                   SimpleFileReader.openFileForReading("fileName.text");
              } catch (FileNotFoundException fnfe) {
                   System.out.println("");
              }This is part of a method, if that helps. In Eclipse I get the error message "Unreachable catch block for FileNotFoundException. This exception is never thrown from the try statement body." I saw another post similar to this one, but it's not quite clear what the solution is. Could anyone clarify for a beginner?
    Thanks

    It actually does if the file it's opening is not really a text file, or if it's read-protected. Or is that where I'm going wrong? I'm just trying to open the file's name(already in the field) and know that it is .text or will return the error.
    Edited by: meme_kun_345k on Jan 15, 2008 7:18 PM

  • Exception: java.lang.NoClassDefFoundError thrown from the UncaughtException

    Exception in thread "main"
    Exception: java.lang.NoClassDefFoundError thrown from the UncaughtExceptionHandler in thread "main"
    I dont know why, but after 3 hours of processing I get this error. I encapsulated my main with try/catch but nothing is caught. Nor is there a traceback.
    [gat@asus dist]$ java -Xdiag -XshowSettings:vm -Xint -jar jgps.RTI.jar localroads
    VM settings:
    Max. Heap Size (Estimated): 1.73G
    Ergonomics Machine Class: server
    Using VM: Java HotSpot(TM) 64-Bit Server VM
    [gat@asus dist]$ java -version
    java version "1.7.0_06"
    Java(TM) SE Runtime Environment (build 1.7.0_06-b24)
    Java HotSpot(TM) 64-Bit Server VM (build 23.2-b09, mixed mode)

    I don't have any idea to offer on what the problem is. However, here are some suggestions:
    Perhaps you can provide an example of your code and/or a more through description of what it does so someone might see something wrong with the code.
    I assume you print out the entire stack trace using somthing like this, so you can get the entire stack trace:
    } catch (Exception e) {
    e.printStackTrace();
    and not something like this:
    System.out.println( e.getMessage());
    You can also consider peppering your code with System.out.println() statements (or write to the log file) to get a better understanding of whats going on and where it crashes.
    What is jgps.RTI.jar? Is that a jar file you created or a vendor jar file? If its a vendor jar file, you might research their web site on how to use it.

  • Exception handling that never ends...

    Hi,
    I've been putting the finishing touches on a project I'm working on, and right now I'm "fixing" some of the error handling. I realized that lots of times when I catch an exception, the program never returns to where it left off. Most of these errors would normally be fatal, but since it's important that this particular application does not terminate (ever) I basically just call a method in the main class that resets the application.
    The problem, I'm thinking, is that java keeps a place on the stack to return to the statement after the error occurred -- and since this will never happen, I can imagine a lot of unnecessary placeholders eventually overflowing the stack. This would be bad since it's our plan to have this application running on our shop floor for days/months/years at a time with minimal intervention!
    But I'm fairly new to java, and maybe I'm just paranoid. Is my understanding of this situation correct? Can I avoid it?
    Thanks for any input.

    Okay, here is some code. By the way, only on unrecoverable errors do I want to log the user off and reset the application. The reason I'm doing this is because 1) I don't want the application to exit 2) It's possible that the problem is with that particular users account, and the next user might be okay. This is an application running in a kiosk where people will be lining up to use it, and if it can at all stay up it ought to!
    One final note before I paste in the code... My application is admittedly not as robust as it could be, but only because my database interface is really an XML API provided by a third-party. The API is limited, so there are only so many things I can do to recover from an error!
    Ok, here's some code. It's not my actual application since that would be thousands of lines of code, but it's an example application I set up that illustrates my problem. It simulates a logon and tries to do 3 transactions but fails on the second one. At that point I would like it to simply "reset" itself for the next user and never do the third transaction, but the third transaction inevitably gets done. What do you think?
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class MainClass
         private class MyDialog extends JDialog implements ActionListener
              private JButton myButton = new JButton();
              MyDialog(String buttonText)
                   this(null, buttonText, true, buttonText);
              public MyDialog(JFrame parent, String title, boolean modal, String buttonText)
                   super(parent, title, modal);
                   myButton.setText(buttonText);
                   myButton.addActionListener(this);
                   this.setSize(400,400);
                   this.getContentPane().setLayout(new GridBagLayout());
                   this.getContentPane().add(myButton);
              public void actionPerformed(ActionEvent e)
                   this.hide();
         MyDialog logon = new MyDialog("Logon");
         MyDialog form = new MyDialog("Do some stuff");
         public MainClass()
         public static void main(String[] args)
              MainClass m = new MainClass();
              System.out.println("Logging on...");
              m.logon.show();
              System.out.println("Showing form...");
              m.form.show();
              for (int index = 1; index <= 3; index++)
                   try
                        System.out.println("Doing transation " + index + "...");
                        m.doTransaction(index);
                   } catch (Exception e)
                        System.out.println("Resetting due to error...");
                        m.reset();
              m.logoff();               
              System.exit(0);
         private void reset()
              logoff();
              System.out.println("Loggin on...");
              logon.show();
              System.out.println("Showing form...");
              form.show();
         private void doTransaction(int data) throws Exception
              System.out.println("Sending data to database...");
              //Simulate an error occurring
              if (data % 2 == 0)
                   System.out.println("Error occurred!");
                   throw new Exception();
         private void logoff()
              System.out.println("Logging off...");

  • A movie I downloaded never fully downloaded so when I try to play it it says it was already purchased and to go to Downloads to manage. Where is "Downloads?"

    A movie I downloaded never fully downloaded so when I try to play it it says it was already purchased and to go to Downloads to manage. Where is "Downloads?"

    Hello Jtc66,
    Thank you for using Apple Support Communities.
    For more information, take a look at:
    iTunes: Finding lost media and downloads
    http://support.apple.com/kb/ts1408
    Downloading past purchases from the iTunes Store, App Store, and iBooks Store
    http://support.apple.com/kb/ht2519
    Have a nice day,
    Mario

  • When I check my iCloud backup it says it has never backed up and when I try to back manually it gives a message of " estimating back up time" and doesn't back up even after having left it for many hours?

    When I check my iCloud backup it says it has never backed up and when I try to back manually it gives a message of " estimating back up time" and doesn't back up even after having left it for many hours?

    Yes I have tried that last weekend ad this weekend. I have tried wi fi at different times of the day too; in case it is speed issue. I have tried selecting only backing up limited content and not every thing per what other users suggest.
    It's maybe either the router is lousy or there is something wrong with my software or hardware.
    Appreciate your thoughts
    Thanks!!

  • Exception logged but not thrown on invocation of webservice (BEA-000905)

    Using webservices.jar that comes with Weblogic SP3 and ant task clientgen to build the client, I got this warning on console:
    <14/Abr/2005 16H00m BST> <Warning> <Net> <BEA-000905> <Could not open connection with host: localhost and port: 7777.>
    Of course, weblogic is right, localhost:7777 is not listening, but the problem is that the application does not know this, since no exception is thrown. I'm catching for a Throwable and I get nothing. This is severe because I'm changing the state of some records in a DB table if the invocation of the webservice is OK, i.e., if no exception is thrown. But there really is a connection exception...
    Can anyone help?

    Just to clarify: the warning is logged when invoking a webservice and the target machine is down. I'm sniffing the communication through localhost:7777 (so this is the target machine for the invocation), and then it redirects the request to the machine where the webservice is hosted.
    I was expecting to catch an exception like IOException or RemoteException, or even a custom exception that I defined in the throws clause of the webservice method.

  • Firefox keeps saying the connection is untrusted... I save the exception, yet it NEVER works, everytime I use the same websites I have to "save the exception" again! What can I do to stop this, I'm about to throw in the towel!

    I used certain secured websites every day. And every day, I get the same old "connection is untrusted" messages, on every one of those websites. I do know the "add exception" thing, and I do add the exception for said websites... yet every time I start a new sessions, the exception hasn't been stored, and I have to do it all over again. It's getting really frustrating to use Firefox, since I am sick and tired of adding exceptions that aren't getting stored. I haven't added any new add-ons, only thing I have is Mc-Afee Site Advisor , and I had the same problem before I had to upgrade my Windows XP to Windows 7. One day it was working fine, then it started giving me trouble out of nowhere without new software or extension or anything being added. Nothing I've found online works, and I'm desperate for an answer.

    You can retrieve the certificate and check who issued the certificate.
    * Click the link at the bottom of the error page: "I Understand the Risks"
    Let Firefox retrieve the certificate: "Add Exception" -> "Get Certificate".
    * Click the "View..." button to inspect the certificate and check who is the issuer.

  • Exception caught and not thrown (CF9 Server)

    Hello, everyone.
    I've recently started seeing a JavaScript error with EVERY click of any link on the site.
    (I know this isn't the JavaScript forum - please give this a glance.. it's CF related, I promise.)
    I've tracked it down to "cfajax.js", which is not being included in any documents by any of the developers on this project, so I'm assuming it's something that is being included by the CF9 Server.  Apparently, there is some sort of issue with "parseJSON" that I can't quite figure out.
    Has anyone run into this, before, or heard of it?  Any ideas or suggestions as to what could be causing the error messages?  I'm running out of ideas.
    Thanks,
    ^_^

    I accidentally tracked down the issue.  (How weird is that?)
    The problem: Because we are in a clustered environment, we cannot use CFFILE or CFDIRECTORY - we are supposed to use CF_SANFILE and CF_SANDIRECTORY.  Well.. for some reason, and I do not have any idea WHY.. the CF Server took an exception to one of the CF_SANDIRECTORY tags, so that's where the break was happening, and instead of giving me an accurate explanation of why, it decided to just mess with the cfajax.js functionality, instead.
    I love my job.
    I love my job.
    I love my job.
    I love my job.
    I love my job.
    If I keep saying it, maybe I'll believe it, one day.
    Thanks to everyone for your input/suggestions.
    ^_^

  • An unknown website just appeared in my 'exceptions' list (Tools Options Security "warn me when sites try to install add-ons"-how could this happen?

    downloaded Firefox onto friends' laptop last night. Found it necessary to place two websites in the (afore-mentioned) "Exceptions" category. shut down/re-booted three-four times over the next few hours before shutting down the laptop and going to bed. Booted up this am and, WHOA!-suddenly my menu/toolbars have new, undesired toolbars(?) search boxes(?): the search box, if I remember right, was labeled "My Web Search sponsored by iwon!" Whilst eliminating the intruders I became aware that by some unknown means I had fetched up on some webpage I've never heard of and had no reason to go to-( the very top of my display (above the menu and address bar) read: 'reason upgrade Search' (separated by a line symbol I can't reproduce here), then 'Musician's Friend' ....HUH? (feeling like Dorothy w/o a tornado transport). So I finish getting rid of the invaders and check out my History to try to figure out how I wound up at this website. my history indicates the last site I visited before going to bed, then 'aclk' (www.google/aclk? followed by a string of mixed symbols letters etc. Then 'redirect' (www.rkdms.com/redirect?c=....and a string of numbers and letters. Then the website"reason upgrade Search (?) Musician's Friend " then 'redirect.jhtml' (www.search.mywebsearch.com/mywe.........) Them 'Firefox Web Browser& Thunder....' still no clue how or why I wound up at that site..didn't go there, (not of my volition, anyways!!) so im checking my security settings and in Tools>options>Security>advanced> in the "Exceptions" category of "Warn me when sites try to install add-ons" is a website I've never heard of (getpersonas.com) and DID NOT enter!!!!!!!.Need to know how this could happen, how to prevent recurrence and how hard should I hit the panic button because right now I'm totally freaked!
    == today

    These prefs get set to an empty String once the sites have been added to the whitelist if the pref is not empty if you open the exception window.
    Tools > Options > Security : "Warn me when sites try to install add-ons": Exceptions
    You can reset these prefs on the about:config page.
    xpinstall.whitelist.add - addons.mozilla.org
    xpinstall.whitelist.add.36 - getpersonas.com
    To open the ''about:config'' page, type '''about:config''' in the location (address) bar and press the Enter key, just like you type the url of a website to open a website.
    If you see a warning then you can confirm that you want to access that page.

  • HT1212 Reset does not work on disabled Ipod touch.  I did the never synced device option on a computer that we have never synced with.  Still says try again in 22,462,172 minutes.  Itunes says it cannot sync also.  Any ideas???

    Reset does not work on disabled Ipod touch.  I  performed the reset procedure Apple recommended and it did not work(Never synced device with itunes).  Comes back to try again in 22,462,160 minutes.  I tunes says Ipod is locked and can not access.  Any ideas???
    Thank you

    Place the iPod in Recovery Mode and then connect to your computer and restore via iTunes. The iPod will be erased.
    iOS: Wrong passcode results in red disabled screen
    If recovery mode does not work try DFU mode.
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings

  • Windows migration assistant never gets inventory completed - what to try to disable?

    I recently downloaded Mountain Lion, and want to move my key content from my Vista-based 64-bit windows laptop to the Macbook Pro. the initial migration attempt during Mountain Lion install failed - same exact symptom.
    Both laptops connect via my home wi-fi, and establish security code, but the inventory never appears.
    On the windows vista machine the green scroll bar just slides and slides (after 4 hours I aborted it).
    On the Mackbook Pro, the windmill spins and spins while the machine says that the Migration Utility is collecting the inventory from my other machine.
    I have insured that McAfee is disabled, as well as windows updater, and end processes directly from the Task Manager that were not required.
    How do I get over this hump?
    Thanks.

    Is your MBP new? If so take it and your old PC to the Apple store and they will do it for you.

Maybe you are looking for

  • Tree In TableView Using Iterator

    Can I creat a Tree in a TableView using Iterator( Which is implemented as a local class in a Model Class)

  • Document management system using oracle text

    i plan to create document management system using oracle text with following features 1) document comparision 2) document search and more... can oracle text be used to display documents of various formats by converting them to HTML. and can search ke

  • Urgent! - unexpected error -- need help!!

    Hi, all. I'm a photographer on a tight deadline and need to upload pictures to my lab. The program uses java and it's been working fine for months since I first started using it. Now, all of the sudden, when I try to upload pictures online to my lab

  • ITSmobile - me53 - Table not displayed

    Hello all, we are trying to configure ITSmobile for some standard transactions in our ECC 6 EHP6 system. We are following the steps which are listed in help.sap.com link (http://help.sap.com/saphelp_nw70/helpdata/en/46/6d41e42dc56a58e10000000a11466f/

  • IOS5 - Erratic Notification centre behaviour on iPad 1 when displaying calendar entries

    Anyone else having an issue when enabling Calendar events to be displayed in the notification centre - where the notification centre scrolls up and down, adding and deleting entries constantly? (as if it's in a loop from ****)