Unreachable catch block????  what is this???

I have created a try-catch statement, I have also created a home made Invalid value exception class. I have also thrown the InvalidValueException in a calculate method in a seperate class. I am getting the error of unreachable catch block. Here is my code for this process. Please Help
private void runPayroll(List employees)
Collections.sort(employees, new PersonComparator());
// place the following code in a try-catch statement to check for the following errors
//- InvalidValue (the pay units must be a decimal number > 0)
try
double payRate = Double.parseDouble(jtfPayRate.getText());
catch (InvalidValueException ivEx)//THIS IS WHERE I AM GETTING MY ERROR
JOptionPane.showMessageDialog(this, "the pay units must be a decimal number > 0", "Error Message", JOptionPane.ERROR_MESSAGE);
return;
// loop through all of the employees in the collection
Iterator iterator = employees.iterator();
StringBuffer output = new StringBuffer("");
while (iterator.hasNext())
Employee employee = (Employee)iterator.next();
output.append( employee.toString() + "\n" );
//InvalidValueException class
public class InvalidValueException extends Exception
public  InvalidValueException(double payUnit)
  super(payUnit);  //I SM GETTING THE ERROR The constructor Exception (double) is undefined  PLEASE HELP
public String getLocalizedMessage()
return "Amount must be > 0";
//PayCheck class this is where I throw the exception
public abstract double calculate(double payUnit, double payRate)
throws InvalidValueException;
public void calculateTax() throws InvalidValueException
FICAOwed = grossPay * FICA;
federalOwed = grossPay * federalTax;
stateOwed = grossPay * stateTax;
}     

Sorry did not mean to post twice. I made some changed from the responses, but Iwas not getting this error.
I have changed the code to this but now I am getting an error because the getText() returns a String. I need to check for a valid double could you help me with this.
try
double payRate = jtfPayRate.getText();
catch (InvalidValueException ivEx)//THIS IS WHERE I AM GETTING MY ERROR
JOptionPane.showMessageDialog(this, "the pay units must be a decimal number > 0", "Error Message", JOptionPane.ERROR_MESSAGE);
return;
}

Similar Messages

  • *YOUR APPLE COMPUTER HAS BEEN BLOCKED* what does this mean?

    MY macbook air show this pop up every time that i open safari or chrome!
    http:\\devicetvr.com
    YOUR APPLE COMPUTER HAS BEEN BLOCKED
    Mac system alert!
    and a telephone number 1  696 0555
    when i called to them they asked me for 480$

    Faseleh wrote:
    Could you please tell me what should i do?
    Your Mac has been compromised, erase it and restore data only from a backup that is earlier than when you gave the criminals access to your Mac. You should also change all passwords/logins for all credit cards, online accounts and government info (social security number etc)
    You should do this now.

  • When downloading, a RED astrick appears as file catches download WHAT IS THIS????

    NOT JUST FIREFOX anything i try to download! i am no expert thats for sure so HELP!!

    Can you attach a screenshot?
    *http://en.wikipedia.org/wiki/Screenshot
    Use a compressed image type like PNG or JPG to save the screenshot and make sure that you do not exceed the maximum file size (1 MB).

  • Return statement inside a catch block???

    If you put a return statement inside of a catch block, what statements will be executed next? I.e., what happens to the flow of control?

    If you put a return statement inside of a catchblock, what statements will be executed next? I.e.,
    what
    happens to the flow of control?If you write a short testing sample, compile it and
    run it, what do you get as a result ?
    Eek! That actually involves effort! Are you kidding?Kidding ? Me ?
    I'd better waste my time writing programs for lazy OPs !
    ;)

  • I am trying to activate my iPhone. I am seeing a message saying "a server problem is blocking Apple ID sign in. Try signing in later." What is this?

    I am trying to activate my new Verizon Iphone. I am getting a message saying "A server problem is blocking Apple ID sign in. Please try again later." What is this and it seems to be persisting.........can't activate my long awaited new phone!

    Hi Natalie,
    I was able to workaround this issue by clicking the "Skip" option on the first screen.  Afterwards, I went back and manually entered my me.com Apple ID in Settings | iCloud and my iTunes Apple ID in Settings | Store.  Doing it this way doesn't ask you to enter your birthday and I haven't yet found where that is supposed to be set.  However, everything appears to be working correctly without it.  Hope this helps!
    Brad

  • What is this Labview function block ? (-1 gain figure with red arrow on top)

    Hello all,
    I came across this code which has a function with -1 gain figure with red arrow on top ? 
    What is this function and where can I find it ?
    Thanks

    decrement ptbypt

  • Can't find class because of try catch block ?!

    Hello,
    I'm using the JNI to use a java library from my c++ code.
    JNI can't find the "Comverse10" class below, but when i put the try catch block in createMessage in comment, FindClass succeeds ?!
    Unfortunatly i need the code inside the try block ;-)
    I tried a few things, but none of them worked:
    - let createMessage throw the exception (public void createMessage throws ElementAlreadyExistsException ), so there isn't a try catch block in createMessage => result: the same
    - make a "wrapper" class Comverse that has a Comverse10 object as attribute and just calls the corresponding Comverse10.function. Result: Comvers could be found, but not constructed (NewObject failed).
    Can someone tell me what is going on ?!
    Thank you,
    Pieter.
    //Comverse10 class
    public class Comverse10 {
    MultimediaMessage message;
    /** Creates a new instance of Comverse10 */
    public Comverse10() {
    public void createMessage() {
    TextMediaElement text1 = new TextMediaElement("Pieter");
    text1.setColor(Color.blue);
    SimpleSlide slide1 = new SimpleSlide();
    //if i put this try catch block in comment, it works ?!
    try{
    slide1.add(text1);
    catch(com.comverse.mms.mmspade.api.ElementAlreadyExistsException e){}
    MessageContent content = new MessageContent();
    content.addSlide(slide1);
    this.message = new MultimediaMessage();
    message.setContent(content);
    message.setSubject("Mijn subjectje");
    for those of you who are intersted: here's my C++ code:
    //creation of JVM
    HRESULT Java::CreateJavaVMdll()
         HRESULT HRv = S_OK;
    char classpath[1024];
         jint res;
         if(blog)     this->oDebugLog->Printf("CreateJavaVMdll()");
         strcpy(classpath,"-Djava.class.path="); /*This tells jvm that it is getting the class path*/
         strcat(classpath,getenv("PATH"));
         strcat(classpath,";D:\\Projects\\RingRing\\MMSComposer;C:\\Progra~1\\j2sdk1~1.1_0\\lib");     //;C:\\Comverse\\MMS_SDK\\SDK\\lib\\mail.jar;C:\\Comverse\\MMS_SDK\\SDK\\lib\\activation.jar;C:\\Comverse\\MMS_SDK\\SDK\\lib\\mmspade.jar
         //------Set Options for virtual machine
         options[0].optionString = "-Djava.compiler=NONE"; //JIT compiler
         options[1].optionString = classpath;                                        //CLASSPATH
         //------Set argument structure components
         vm_args.options = options;
         vm_args.nOptions = 2;
         vm_args.ignoreUnrecognized = JNI_TRUE;
         vm_args.version = JNI_VERSION_1_4;
         /* Win32 version */
         HINSTANCE hVM = LoadLibrary("C:\\Program Files\\j2sdk1.4.1_01\\jre\\bin\\client\\jvm.dll");
         if (hVM == NULL){
              if(blog) oDebugLog->Printf("Can't load jvm.dll");
              return E_FAIL;
         if(blog) oDebugLog->Printf("jvm.dll loaded\n");
         LPFNDLLFUNC1 func = (LPFNDLLFUNC1)GetProcAddress(hVM, "JNI_CreateJavaVM");
         if(!func){
              if(blog)     oDebugLog->Printf("Can't get ProcAddress of JNI_CreateJavaVM");
              FreeLibrary(hVM);     hVM = NULL;
              return E_FAIL;
         if(blog)     oDebugLog->Printf("ProcAddress found");
         res = func(&jvm,(void**)&env,&vm_args);
         if (res < 0) {
    if(blog)     oDebugLog->Printf("Can't create JVM with JNI_CreateJavaVM %d\n",res);
    return E_FAIL;
         if(blog)     oDebugLog->Printf("JVM created");
         return HRv;
    //finding Comverse10 class:
    HRESULT CALLAS MMSComposer::InitializeJNI(void)
         HRESULT HRv=E_FAIL;
         DWORD T=0;
         try
              if(blog)     oDebugLog->Printf("\nInitializeJNI()");
              bJVM = FALSE;
              jni = new Java(oDebugLog);
              if(jni->CreateJavaVMdll()!=S_OK){
                   if(blog)     oDebugLog->Printf("CreateJavaVMdll() failed");     
                   return HRv;
              jclass jcls = jni->env->FindClass("Comverse10");
              if (jcls == 0) {
    if(blog)     oDebugLog->Printf("Can't find Comverse10 class");
                   jclass jcls2 = jni->env->FindClass("test");
                   if (jcls2 == 0) {
                        if(blog)     oDebugLog->Printf("Can't find test class");
                        return HRv;
                   if(blog)     oDebugLog->Printf("test class found %08x",jcls2);
    return HRv;
              if(blog)     oDebugLog->Printf("Comverse10 class found %08x",jcls);
              jmethodID mid = jni->env->GetMethodID(jcls , "<init>", "()V");
              if (mid == 0) {
                   if(blog)     oDebugLog->Printf("Can't find Comverse10() constructor");
    return HRv;
              if(blog)     oDebugLog->Printf("Comverse10() constructor found");
              jobject jobj = jni->env->NewObject(jcls,mid);
              if(jobj==0)
                   if(blog)     oDebugLog->Printf("Can't construct a Comverse10 object");
    return HRv;
              if(blog)     oDebugLog->Printf("Comverse10 object constucted");
              //Create Global reference, so java garbage collector won't delete it
              jni->jobj_comv = jni->env->NewGlobalRef(jobj);
              if(jni->jobj_comv==0)
                   if(blog)     oDebugLog->Printf("Can't create global reference to Comverse10 object");
    return HRv;
              if(blog)     oDebugLog->Printf("global reference to Comverse10 object %08x created",jni->jobj_comv);
              bJVM=TRUE;
              HRv=S_OK;
         }     catch( IDB * bgError ) { throw bgError->ErrorTrace("InitializeJNI::~InitializeJNI",HRv, 0, T); }
              catch(...) { throw IDB::NewErrorTrace("InitializeJNI::~InitializeJNI",HRv, 0, T ); }
              return HRv;

    >
    I would guess that the real problem is that that the
    exception you are catching is not in the class path
    that you are defining.Thanks jschell, that was indeed the case.
    I don't have the docs, but I would guess that
    FindClass() only returns null if an exception is
    thrown. And you are not checking for the exception.
    Which would tell you the problem.Ok, i'll remember that. But what with exceptions thrown in my java code, the documents say
    // jthrowable ExceptionOccurred(JNIEnv *env);
    // Determines if an exception is being thrown. The exception stays being thrown until either the native code calls ExceptionClear(), or the Java code handles the exception
    so, what if the java code throws an exception and catches it, will i be able to see that in my c++ code with ExceptionOccurred ?
    or
    should the java method be declared to throw the exception (and not catch it inside the method)
    Again, thank you for your help, it's greatly appreciated !

  • How to get the returned error messages in the Try/Catch block in DS 3.0?

    A customer sent me the following questions when he tried to implement custom error handling in DS 3.0. I could only find the function "smtp_to" can return the last few lines of trace or error log file but this is not what he wants. Does anyone know the answers? Thanks!
    I am trying to implement the Try/Catch for error handling, but I have
    hard time to get the return the msg from DI, so I can write it to out
    custom log table.
    Can you tell me or point me to sample code that can do this, also, can
    you tell me which tables capture these info if I want to query it from
    DI system tables

    Hi Larry,
    In Data Services XI 3.1 (GAd yesterday) we made several enhancements for our Try/Catch blocks. One of them is the additional of functions to get details on the error that was catched :
    - error_message() Returns the error message of the caught exception
    - error_number() Returns the error number of the caught exception
    - error_timestamp() Returns the timestamp of the caught exception.
    - error_context() Returns the context of the caught exception. For example, "|Session Datapreview_job|Dataflow debug_DataFlow|Transform Debug"
    In previous versions, the only thing you could do was in the mail_to function specify the number of lines you want to include from the error_log, which would send the error_log details in the body of the mail.
    Thanks,
    Ben.

  • Return in finally block hides exception in catch block

    Hi,
    if the line marked with "!!!" is commented out, the re-thrown exception is not seen by the caller (because of the return in the finally block). If the line is commented in, it works as I would expect. Is this is bug or a feature? I assume the return removes the call to troubleMaker() from the call stack - including the associated exception...
    Christian Treber
    [email protected]
    public class ExceptionDemo extends TestCase
    public void testException()
    String lResult = "[not set]";
    try
    lResult = troubleMaker();
    System.out.println("No exception from troubleMaker()");
    } catch(Exception e)
    System.out.println("Caught an exception from troubleMaker(): " + e);
    System.out.println("Result: " + lResult);
    public String troubleMaker()
    boolean lErrorP = false;
    try
    if(6 > 5)
    throw new RuntimeException("Initial exception");
    return "normal";
    } catch (RuntimeException e)
    System.out.println("Caught runtime exception " + e);
    lErrorP = true;
    throw new RuntimeException("Exception within catch");
    } finally
    System.out.println("Finally! Error: " + lErrorP);
    if(!lErrorP)
    return "finally";

    This is specified in the Java Language Specification, section 14.19.2 .
    -- quote
    If execution of the try block completes abruptly because of a throw of a value V, then there is a choice:
    * If the run-time type of V is assignable to the parameter of any catch clause of the try statement, then the first (leftmost) such catch clause is selected. The value V is assigned to the parameter of the selected catch clause, and the Block of that catch clause is executed. Then there is a choice:
    o If the catch block completes normally, then the finally block is executed. Then there is a choice:
    + If the finally block completes abruptly for any reason, then the try statement completes abruptly for the same reason.
    -- end quote
    "completing abruptly" (in this instance) means a throw or a return, as specified in section 14.1
    Ok? It's not a bug, it's the defined behaviour of the language. And when you think about it, this behaviour gives you the option to do what you want in your finally block.

  • Return statement in catch block !

    Hello Java Gurus,
    The code is not compiling when i remove return from the catch block
    i dont really understand the essence of return statement in catch block
    any help is greatly appreciated !
    Thanks in advance !
    import java.io.*;
    public class fileinputstream  {
       public static void main(String arg[]) {
            FileInputStream fin ;
            FileOutputStream fout;
           try  {
                 fin =new     FileInputStream("input_file.txt");
                 int bytes_av = fin.available();
                 System.out.println("bytes available the input file "+bytes_av);
           catch(FileNotFoundException e)
               System.out.println("The input file is not present");
               return;
           catch(IOException e)
               System.out.println("error while giving bytes available the input file");
               return;
           try
                     fout =new FileOutputStream("output_file.txt");
           catch(FileNotFoundException e)
               System.out.println("The output file cannot be created");
               return;
           int data=0;
           try  {
               data =(int)fin.read();
           catch(IOException e) {
               System.out.println("Exception while reading from file");
            while(-1!=data)      {
                       try
                       fout.write(data);
                       catch(IOException e)
                           System.out.println("Error while writing to file");
                       try
                           data =(int)fin.read();
                       catch(IOException e)
                           System.out.println("Exception while reading from file");
            try  {
                   fin.close();
                   fout.close();
            catch(IOException e)  {
               System.out.println("Error while closing files");
    }

    You do understand what "return" means, don't you? It
    exits the method, main() in this case.
    So the return statements in the catch blocks end the
    program. If you remove the return statements, the
    program will continue with the code after the catch
    blocks. It needs the variables "fout" and "fin"
    there, and these must be initialised.
    If there are no return statements in the catch
    blocks, the variables "fin" and "fout" will be not
    initialized when you get to the code that uses them,
    and that's an error. The java compiler is telling you
    that you must always initialise the variables (you
    can set them to "null", for example).Great explanation !!!
    Thanks !

  • Return statement at the end of try or after catch blocks

    Hi
    Can anyone tell me which is the better practice - to put the return statement at the end of try block or after all the catch blocks ie at the end of method.
    Eg
    Method A()
    String str;
    try{
    str= [some code]
    return str
    catch(Exception e)
    System.out.println("Exception");
    } // end of method
    OR
    Method B()
    String str;
    try{
    str= [some code]
    }catch(Exception e)
    System.out.println("Exception");
    return str
    } // end of method

    I always try to work with only one exit point for each method.
    For readability I always put the return statement as close to the end of the method as possible.
    In this particular question,
    I think you should put the return at the end of the method (for readability, since this is what you are
    familiar with), but when I have a try-catch clause, I usually have an unrecoverable error and
    should throw this further down the tree, so it usually becomes
    try{
       return   
    }catch(...){
       // write out some logging information
       rethrow exception or throw another exception
    }I think you should NEVER reflect the occurence of an error in the return-value of the
    method when an unrecoverable exception occurs. Just rethrow this exception or throw another method.
    Other methods look like
       Object result = new...
       return result;As for the specific case of a repetitive if-case:
    This is possible in two versions:
    With one return and a result-object
    Object result = new ...
    if(..)
       result = ...
    else if(..)
       result = ...
    return result;With every time a return
    if(...)
       return ...;
    else if(...)
       return ...;For me the above two possibilities make no difference,
    but I find the second version (which I hated when I began programming)
    to be somewhat more of a (self-made) standard nowadays.
    But I do not think this particular case makes much of a difference.
    kind regards,

  • Use catch block to do something other than handling exception?

    Hello,
    I have always been under the impression that the catch block should only handle the exception thrown by the try block?
    But now I'm reading a class where it's more or less used as an else if. Of course this works well, but I don't like it.
    What is your view of this? A little example:
    FileReader fR = null;
    try{
          fR = new FileReader("file1")
    catch (Exception e){
         //If file1 didn't exist try if file2 exists
         try{
             fR = new FileReader("file2")
         catch (Exception ee){
    }I think it should be rewritten not using this technique?

    Farmor wrote:
    Hello,
    I have always been under the impression that the catch block should only handle the exception thrown by the try block?
    But now I'm reading a class where it's more or less used as an else if. Of course this works well, but I don't like it.
    What is your view of this? A little example:
    FileReader fR = null;
    try{
    fR = new FileReader("file1")
    catch (Exception e){
    //If file1 didn't exist try if file2 exists
    try{
    fR = new FileReader("file2")
    catch (Exception ee){
    }I think it should be rewritten not using this technique?There's nothing really wrong with the code you posted, but I find it ugly to write additional non-error-handling code inside nested try-catches. What happens if you want to extend this logic to 3 or 4 files? If the code could be written to avoid it, as someone else showed, I'd prefer the other way.
    I'd put the file names in an array, and loop over the array until I found one I could open.

  • How to use Try Catch Block in ABAP Like JAVA

    Hi Experts,
       I am using BAPI to post MIGO in one of my application. If the MIGO is successfully gets posted then BAPI returns no message, but if there is some error in posting then it returns an error message. Now I want to print that error message in catch block by calling method RAISE_ERROR_MESSAGE. How to use try catch block in ABAP. Please suggest with example.
    Thanks and Regards.
    Vaibhav Tiwari.

    Hi Vaibhav
    You may not catch exceptions returned by function module using try endtry block.
    It works well with the exception returned by methods.
    In case of function modules or BAPI what u can do is to check sy-subrc returned and give message accordingly. If it returns a structure like bapireturn then display message returned.
    in case of exception returned by a method,  do it like this...
    data: excep type cx_root.
    data: v_str type string.
    try.
    *any method call or division by zero (for ex)
    catch cx_root into excep.
    endtry.
    if  excep is not initial.
    CALL METHOD   excep->if_message~get_text
      receiving
        RESULT = v_str.
    endif.
    *display the value returned in v_str on screen

  • What is this error?

    I am using a try, catch, block with parseint and I am getting the following error when I compile.
    cannot find symbol - method readline()
    This is the line of code:
    convertedInt = Integer.parseInt(br.readline());And this is all of the code:
    import java.io.*;
    public class GradeCalculator
    private int convertedInt;
    public GradeCalculator(){ //create BufferedReader to grab input from user
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      System.out.println("Enter grade for year one"); //Prompt the reader to input a grade
      try{ //try to read the input and convert the input to an integer
       convertedInt = Integer.parseInt(br.readline());
      catch(NumberFormatException nfe){ //catches any error and tells the user what the issue is
       System.out.println("Please enter a numeric value only e.g. 1. Please try again");
       //Uncomment the line below if you want a stack trace of the error
       //nfe.printStackTrace();
      //Enter the rest of your code here
    public static void main(String [] args){
      GradeCalculator gc = new GradeCalculator();
    Is the code trying to call a method called readline()?
    Is their a good site designed to help you overcome errors and recognise what they are as the help option does not offer much
    Thanks

    Spangle1187 wrote:
    You took the time to answer my question and for that I am grateful. I am struggling at the moment and what I have been googling up until now has left me baffled.Hey, tell me that you tried searching and that's all I need to hear. I have no problem with questions that come after making an attempt at independent research. That's why in my first reply I said "Google first, ask here second."
    As George hinted, it does get annoying as a volunteer when it appears that the poster is really trying to just be a proxy between us, the volunteers, and the poster's problem/code. Hence we tend to react to threads that follow this pattern: "I have some issue.../Here's the solution/Okay but now it says this.../Then do this..." as, when it seems like the poster isn't actually trying to work out the problems in between posts, we are basically just being asked to do the poster's work for them. So just show that effort, ask [smart questions|http://catb.org/~esr/faqs/smart-questions.html] and we have no problem.
    Sorry if my questions are keeping you from more useful questionsThe question isn't useful or useless in itself, and it has little to do with how advanced the subject matter is. I consider a useless question to be one where the asker is asking without making an effort to explore the issue independently. Useless because it hasn't been shown to me that answering it will give anything to society that hasn't already been given.
    After that, the question can be as novice or advanced, simple or complex as possible, and it won't bother me.

  • Nested try-catch blocks

    Hello All,
    If I have 2 nested try-catch blocks see below
    try{
        //Some code
        try{
            //Code that throws an IOException
        }catch(NumberFormatException nfe){
            //Handle the NFE
    }catch(Exception e){
        //Handle the Exception
    }Now what happens if in the inner try-catch an IOException is thrown? Will it be ignored, or will it get thrown out to the outer one and be caught by that catch?
    Thanks,
    Matt

    Thanks, should have just done this from the start, but here is the result...
    The following code
    public class Main {
         public void execute(){
              try{
                  try{
                       for(int i=0;i<100;i++){
                            System.out.println(i);
                            if(i==5){
                                 throw new java.io.IOException();
                  }catch(NumberFormatException nfe){
                     System.out.println("caught in inner block");
              }catch(Exception e){
                  //Handle the Exception
                 System.out.println("caught in outer block");
         public static void main(String[] args) {
              Main m = new Main();
              m.execute();
    }GENERATES:
    0
    1
    2
    3
    4
    caught in outer block
    Thanks,
    Matt

Maybe you are looking for

  • Master data load error

    Hi I am getting following error while executing the DTP: 0MATERIAL : Data record 84 ('1-80200-01  '): Version '1-80200-01  ' is not valid. I know its because of space and I can correct it in PSA. But its loaded daily as full load and I dont want to c

  • Special Ledger-does delta datasource for totals table work at  4.7

    Has anyone successfully used deltas on special ledger total tables  at 4.7c ? As the totals table doesn’t have a timestamp I want to understand how this works? heres the help line that appears to suggest it should work: http://help.sap.com/saphelp_nw

  • I can't get rid of 169 ip addresses on devices

    I am having problems with computers and iOS devices using a 169.x.x.x address instead of the DCHP address supplied by Charter. This started just recently. The only thing that has changed is I installed Lion a few weeks back. I have gone through three

  • Change Employee Personnel no.

    Hi everyone we have a situation where an employee is moving states but the company we use for payroll will only let us have one State tied to each badge number. So we need to change the employee badge number (Personnel number)  Problem is I don't kno

  • New eSATA only plays back some shows

    Just installed an External Drive over the weekend. It seemed to work fine on Monday & Tuesday. Tonight, however, it will not play back 2 of the shows that were recorded yesterday (Unforgettable & NCIS) it will play back a movie this morning & a TV sh