How do I use try/catch so that it loops until proper input is put in?

So I have a specific thing that I am asking for (double)... if user inputs letters instead i do try/catch... how do I have it loop until user puts in proper stuff?

i think i might have figured it out...
          String first = JOptionPane.showInputDialog("Enter the first number");
          while(num1 != double || num1 != int){
          try{
          num1 = Double.parseDouble(first);
          catch (NumberFormatException e){
               String first = JOptionPane.showInputDialog("Enter the first number");
          }now i need to figure out how to make
num1 != double || num1 != intpart work..

Similar Messages

  • 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

  • Error when using try catch inside oledb command to run stored procedure

    Hi,
    i'm using the below command to run some jobs  using OLEDB Command
    exec sp_start_job @job_name =?
    and it runs successfully
    when i put this code inside try catch block as below , it generates error and don't accept it
    begin try
    exec sp_start_job @job_name =?
    end try
    begin catch
    end catch
    the error message is "Syntax error, PErmission vaiolation or other nonspecific error"
    do you know is there any problem using TRY catch insdie OLEDB command ?
    Thanks ,
    Ahmed Salah

    Hi Ahmed,
    According to your description, if an error raised that fails the package, then you want the package to continue execute.
    To achieve this requirement, we can use Integration Services (SSIS) Event Handlers that we can create custom event handlers for an OnError event when an error occurs to continue processing rest of the package. For more details, please refer
    to the following blog:
    http://visakhm.blogspot.in/2013/03/error-handling-in-ssis-loops.html
    If there are any other questions, please feel free to ask.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Do I always need to use try/catch? [ newbie ]

    Hi,
    I have a method called methodOne that throws ExceptionXXX, and another method called methodTwo that uses methodOne and also throws ExceptionXXX.
    public static methodOne() throws ExceptionXXX
    Does methodTwo need to use try/catch to catch ExceptionXXX from methodOne, ( like the following code )
    public static methodTwo() throws ExceptionXXX
    try
    methodOne();
    catch( ExceptionXXX theException )
    throw new ExceptionXXX;
    or it isn't necessary ( like this code )?
    public static methodTwo() throws ExceptionXXX
    methodOne();
    Thanks for the help,
    Andre

    Hi,
    if you call a mthod w/ a throws declaration you hace two possibilities:
    1. catch the Exception
    2. pass the Exception by adding a throws declaration to the calling method
    So, in your case the second example is a valid way to handle the Exception.
    Also Andre

  • How can I use TopLink for querys that have two and more tables?

    I use TopLink today, and I can use one table to query, but how can I use TopLink for querys that have two and more tables?
    Thank you for see and answer this question.

    You can write a custom SQL query and map it to an object as needed. You can also use the Toplink query language "anyOf" or "get" commands to map two tables as long as you map them as one to one (get command) or one to many (anyOf command) in the toplink mapping workbench.
    Zev.
    check out oracle.toplink.expressions.Expression in the 10.1.3 API

  • [svn:fx-3.x] 10953: Get rid of a try/ catch block that was generating a lot of noise on the heap.

    Revision: 10953
    Author:   [email protected]
    Date:     2009-10-09 10:50:37 -0700 (Fri, 09 Oct 2009)
    Log Message:
    Get rid of a try/catch block that was generating a lot of noise on the heap.
    QE Notes: None
    Doc Notes: None
    Bugs: SDK-23563
    Reviewer: Ryan
    API Change: no
    Is noteworthy for integration: No
    tests: checkintests mustella/Managers/DragManager
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-23563
    Modified Paths:
        flex/sdk/branches/3.x/frameworks/projects/framework/src/mx/managers/dragClasses/DragProxy .as

    Revision: 10953
    Author:   [email protected]
    Date:     2009-10-09 10:50:37 -0700 (Fri, 09 Oct 2009)
    Log Message:
    Get rid of a try/catch block that was generating a lot of noise on the heap.
    QE Notes: None
    Doc Notes: None
    Bugs: SDK-23563
    Reviewer: Ryan
    API Change: no
    Is noteworthy for integration: No
    tests: checkintests mustella/Managers/DragManager
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-23563
    Modified Paths:
        flex/sdk/branches/3.x/frameworks/projects/framework/src/mx/managers/dragClasses/DragProxy .as

  • How can i use the same cursor in a loop fro multipletimes.

    I am using two cursors.One to fetch sites and the other to fetch participants under each site.I am performing some job with that participants data.Now the problem is i am using the 2nd cursor in a loop.So it fetches the data of participants falling under one state.But when it comes to the second state,as the second cursor is already open it is unable to fetch the records.Please help me .How can i use the same cursor in a loop fro multipletimes.
    I am sending the code which i have written in When-Button-Pressed-Trigger...
    declare
         sid number;
         pid number;
    cursor csid is select distinct(site_id) from cyber_ppt;
    cursor cpid is select pc_id,st_dt,ed_dt from cyber_ppt where site_id = sid;
         stdt varchar2(10);
         eddt varchar2(10);
         nom number;
         stmonth varchar2(10);
         edmonth varchar2(10);
         cjan number:=0;
         cfeb number:=0;
         cmar number:=0;
         capr number:=0;
         cmay number:=0;
         cjun number:=0;
         cjul number:=0;
         caug number:=0;
         csep number:=0;
         coct number:=0;
         cnov number:=0;
         cdec number:=0;
         i number:=1;
    begin
         open csid ;
         loop
         fetch csid into sid;
              exit when csid %notfound;
              message(sid);
         open cpid;
         loop
         fetch cpid into pid,stdt,eddt ;
         exit when cpid %notfound;
         message(sid||'-'||pid);
         stmonth:=substr(stdt,4,3);
         edmonth:=substr(eddt,4,3);
         nom:= months_between(eddt,stdt);
    while i <= round(nom)
         loop
         stmonth:=substr(stdt,4,3);
    if stmonth='JAN' then
              cjan:=cjan+1;
    elsif stmonth='FEB' then
              cfeb:=cfeb+1;
    elsif stmonth='MAR' then
              cmar:=cmar+1;
    elsif stmonth='APR' then
              capr:=capr+1;
    elsif stmonth='MAY' then
              cmay:=cmay+1;
    elsif stmonth='JUN' then
              cjun:=cjun+1;
    elsif stmonth ='JUL' then
              cjul:=cjul+1;
    elsif stmonth ='AUG' then
              caug:=caug+1;
    elsif stmonth ='SEP' then
              csep:=csep+1;
    elsif stmonth ='OCT' then
              coct:=coct+1;
    elsif stmonth ='NOV' then
              cnov:=cnov+1;
    elsif stmonth ='DEC' then
              cdec:=cdec+1;
    end if;
         stdt:=add_months(stdt,1);
         i:=i+1;
         end loop;
         end loop;
         end loop;
         end;
         

    try this /* untested */
    DECLARE
    sid           NUMBER;
    pid           NUMBER;
    CURSOR csid IS SELECT DISTINCT(site_id) FROM cyber_ppt;
    CURSOR cpid(nSid NUMBER) is SELECT pc_id,st_dt,ed_dt FROM cyber_ppt WHERE site_id = nSid;
    stdt        VARCHAR2(10);
    eddt        VARCHAR2(10);
    nom         NUMBER;
    stmonth     VARCHAR2(10);
    edmonth     VARCHAR2(10);
    cjan         NUMBER:=0;
    cfeb         NUMBER:=0;
    cmar         NUMBER:=0;
    capr         NUMBER:=0;
    cmay         NUMBER:=0;
    cjun         NUMBER:=0;
    cjul         NUMBER:=0;
    caug         NUMBER:=0;
    csep         NUMBER:=0;
    coct         NUMBER:=0;
    cnov         NUMBER:=0;
    cdec         NUMBER:=0;
    i            NUMBER:=1;
    BEGIN
    FOR rec IN csid
    LOOP
                      sid := rec.csid;
    FOR cRec IN cpid(sid)
    LOOP
                     pid := cRec.pc_id;
                     stdt := cRec.st_dt;
                     eddt := cRec.ed_dt;
    stmonth:=  SUBSTR(stdt,4,3);
    edmonth:= SUBSTR(eddt,4,3);
    nom:= months_between(eddt,stdt);
    WHILE i <= round(nom)
    LOOP
              stmonth := SUBSTR(stdt,4,3);
    IF stmonth='JAN'
    THEN
             cjan:=cjan+1;
    ELSIF stmonth='FEB' THEN
             cfeb:=cfeb+1;
    ELSIF stmonth='MAR' THEN
              cmar:=cmar+1;
    ELSIF stmonth='APR' THEN
              capr:=capr+1;
    ELSIF stmonth='MAY' THEN
              cmay:=cmay+1;
    ELSIF stmonth='JUN' THEN
              cjun:=cjun+1;
    ELSIF stmonth ='JUL' THEN
              cjul:=cjul+1;
    ELSIF stmonth ='AUG' THEN
              caug:=caug+1;
    ELSIF stmonth ='SEP' THEN
              csep:=csep+1;
    ELSIF stmonth ='OCT' THEN
              coct:=coct+1;
    ELSIF stmonth ='NOV' THEN
              cnov:=cnov+1;
    ELSIF stmonth ='DEC' THEN
              cdec:=cdec+1;
    END IF;
             stdt:=add_months(stdt,1);
             i:=i+1;
    END LOOP;
    END LOOP;
    END LOOP;
    END;

  • How can I use active user session that's in an application scope Hashtable?

    First of all, is it possible to use the same session after a user exits and then returns?
    Second, if it is possible, then please tell me what I need to do. So far, this is what I have been doing...
    1.) The user submits login credentials
    2.) The user is authenticated.
    3.) The user does not have an existing session, so a new one is created.
    4.) The user closes the browser.
    5.) The user returns to login page and submits login credentials.
    6.) The user is authenticated.
    7.) The user has an existing session, so it should be used.
    This is where I'm having trouble. All active sessions for my application are stored in a Hashtable. I have been using <%@ page session="false" %> so that a new session is not automatically created. Each time before I create a new session, I check my Hashtable to see if that user has an existing session. If a session exists for that user, then I would like to continue using that session if possible. I have used the methods request.getSession() and request.getSession(false), but a new session is always returned.
    I could create a new session, copy the attributes from the old session(which is stored in my Hashtable) to the new session, and then invalidate the old session, but I'd rather not do that.
    Is there a way that I can use existing sessions that I have stored in my Hashtable?

    First of all, is it possible to use the same session after a user exits and then returns?No, I don't think so. Let me explain why. When the server creates a session object for each client, it needs to know which client is making the request. Remember that HTTP is a stateless protocol. Every time a client makes a request, it sends some sort of session id to the server to let the server know who is trying to make the request. The server will then check to see if a session object exists for that particular client and if so, it will make sure that the max inactive interval (maximum time alloted for that client's session) has not been exceeded. If every thing is okay, then the client can access the session object to get values that were previously placed there. There are many ways that servers try to keep track of clients. One way is to have the clients write the session ID using cookies. But, many people like disallow cookies. So some servers do what is known as URL rewriting. That is, they will write the session ID on the end of the query string. This can also be accomplished programmatically, but it can be taxing to do. Anways, the point is that the client and the server have to have some sort of link between each other and that link is the session ID. So, if the browser is closed, the session ID is lost. That particular client will be forced to get a new session ID the next time the following code is executed:
    //create a session object and set its values
    HttpSession session = request.getSession(true);>
    Second, if it is possible, then please tell me what I
    need to do. So far, this is what I have been doing...
    1.) The user submits login credentials
    2.) The user is authenticated.
    3.) The user does not have an existing session, so a
    new one is created.
    4.) The user closes the browser.
    5.) The user returns to login page and submits login
    credentials.
    6.) The user is authenticated.
    7.) The user has an existing session, so it should
    be used.If you really want to do something like this, you could make up your own ID and store it as a cookie on the client. I've never tried anything like this before so you would have to do your own research. Are you sure you want to do something like this. There is a reason why it works the way it does. There is also a reason why you want to keep the session timeout value some what small. Let me give you an example of some craziness with sessions. A client we once had wanted to keep their sessions open for 4 hours because they said there clients simply did not like to log in all the time. I nearly gasped when I was told we needed to do this. When you make the session time out large (i.e. the maxInactiveInterval( )), then session objects stick around longer in the server. Let's say a client logs into the server and receives a session object. Then, the client makes a few requests. The server knows to keep the session alive as long as the time between requests has not exceeded 4 hours. Then the client closes the browser. How is the server suppose to know that the browser was closed. Well, it doesn't. It just knows to check times between requests. So, that particular session object won't be garbage collected until the session times out. What if a whole bunch of clients did this. Yucko. The server would have a whole bunch of session objects living in memory. What a waste. This is all above and beyond the typical security problems that can arise from having a session open for so long. To make a long story short, you really shouldn't do what you are trying to do unless it is the nature of the app.
    >
    This is where I'm having trouble. All active sessions
    for my application are stored in a Hashtable. I have
    been using <%@ page session="false" %> so that a new
    session is not automatically created. Each time
    before I create a new session, I check my Hashtable
    to see if that user has an existing session. If a
    session exists for that user, then I would like to
    continue using that session if possible. I have used
    the methods request.getSession() and
    request.getSession(false), but a new session is
    always returned.
    I could create a new session, copy the attributes from
    the old session(which is stored in my Hashtable) to
    the new session, and then invalidate the old session,
    but I'd rather not do that.
    Is there a way that I can use existing sessions that I
    have stored in my Hashtable?

  • My iphone 4 button doesn't work. How can I use my phone without that working button?

    my iphone 4 button doesn't work. How can i use my iphone without the working button?

    Well if you restore your iPad that might work. If its a software issue, it might solve it. If that doesn't work, it might be a hardware issue that apple can fix.

  • How do I use/try Encore CS6?

    I wanted to use/try Encore CS6...  Following the instructions it seemed to suggest that I can access the program through the Creative Cloud.  Didn't see anything listed Encore- did some more reading and it seemed to suggest that I could access it through Adobe Premiere Pro.  Doing so didn't seem to work (nothing in the menu)- again did more research and now the wording seems to suggest that I have to buy the product/Creative Cloud in order to use/try Encore...  very confusing.
    Am I missing something?

    2 paths... there is no "try" for Encore, only a paid version due to licensing
    1 - with a paid Cloud subscription, follow ALL of the instructions in http://helpx.adobe.com/encore/kb/encore-cs6-installed-cc.html (there are several steps)
    2 - buy Premiere Pro CS6 as a standalone product... Encore is bundled with PPro
    http://www.adobe.com/products/catalog/cs6._sl_id-contentfilter_sl_catalog_sl_software_sl_c reativesuite6.html?promoid=KFPMZ

  • How can I use my Iphone 5s that was purchased in the US here in the Philippines?

    please let me know

    What do you mean how can you use the phone?  Go out and buy a sim card and put it in the phone to activate it and start using it.

  • How can I use my iPhone 5s that I purchased online

    HHow can I use my iPhone 5s that is locked with someone else's iTunes account?

    If you're able to contact the previous owner, send them this link and tell them to follow its instructions.
    If not, you can't activate the device but may be able to get it refunded.
    Apple won't remove the lock for anyone other than the original owner(assuming they're alive.)
    (112269)

  • IPhone: Using embedded QT movies that either Loop or Loop Back and Forth

    Hi to everyone,
    I'm working on a very simple iPhone app:
    it has several buttons that launch different QuickTime movies embedded in the application, that will either Loop or Loop Back and Forth.
    The desired looping behaviour is already set within QuickTime itself (those settings are available in QuickTime's View menu).
    So far it doesn't seem to work, as the iPhone's SDK doesn't seem to recognize these QuickTime settings of Loop or Loop Back and Forth.
    I've been trying to find advanced documentation on the matter, with no luck.
    Does anyone knows if it's possible to create an iPhone application that has embedded QuickTime movies that either Loop or Loop Back and Forth?
    If it is possible to do so, can you please post some code (or links) explaining how to proceed?
    If the feature is not currently supported, does anyone knows if it will eventually be supported by Apple (maybe in a future SDK revision)?
    While I don't know the entire context the SDK engineering team has to contend with, it seems to me it should be rather simple for Apple's iPhone SDK to simply accept the settings already put in place inside a QuickTime movie.
    Many thanks in advance for any feedback on this!

    Well, my programmers have come back to me and the news is not good.
    The QTMovieLoopsAttribute is not supported in the SDK's QT Kit.
    I'll now call it SDK's *QuickTime Kit Lite*, if you don't mind.
    *QuickTime Kit Lite*, the key audio/video toolbox available for development of applications on the iPhone through the SDK, provides a single option:
    a Play / Stop button.
    The only other thing available (I think) is the option to hide the play/stop controller. That's it.
    Apparently, there are several unofficial, private frameworks that give access to lower-level QuickTime functions and that may provide a way to actually loop videos, but chances are that an app using these unofficial frameworks would get rejected by Apple upon submission for the store.
    I'm still waiting for more info and the final word from my programmers, but from the looks of it, this is going to be a show-stopper shortcoming of QT Kit Lite, as far as my project is concerned.
    I'm probably going to have to fold my project and wait (hope) for an eventual upgrade to the SDK's QT Kit.
    By the way, does anyone knows if there is a way to communicate with Apple and request new features for inclusion in future revisions of the SDK?
    Upgrading the QuickTime Kit librairies to include the video Loop and Loop Back and Forth Attributes would be my first (and only) request.
    many thanks to all!

  • Using a dll function that does not have any inputs from a VI

    Hello all, I'm very new to Labview, I have wraped a dll library using the LVlib wizard and now I am trying to use it in a project.  I have a function that does not take any inputs or return any thing except that a struct is populated with some status information as part of the call.  I am able to draw a StartInterface VI because my void startInterface(const char* configFile, struct status_struct* status) takes the location of a configutation file as an input. But I can not figure out how to connect my Call Library Node to my a function vi that does not have any inputs ( void shutdownInterface(struct status_struct* status)). 
    Note that the status struct is deffined to be only and out put at the creation of the LVLIB.
    Thanks, Mike

    Thanks for the responses guys:
       I think I am aware of the conotations of inputs and outputs when I created the lvlib I specified the argument  struct status_struct* status as only an output instead of the default of input and output.
    I do not think that I am doing anything as complex as function callbacks. My immediate goal is to have an executable (I have application builder) with two buttons and two three text fields one text field for the input of the config file, two text-fields for a cstring that is contained in the status struct; one button to start the interface and one button to stop the interface. 
    This is in all likely hood a case of my self being too dense and missing something fundimental ;-)  I just can't figure out how to wire the shut down method after I've configured the call library node. See the attached pictures:
    Attachments:
    Start.jpg ‏7 KB
    shurtdown.png ‏9 KB

  • How to deal exception using try{}catch{}

    I don't know which is a good way from catch a exception and throw a exception,
    I means that how to use exception in java,catch ? throw?

    Presumably you are not asking the same thing as here...
    http://forum.java.sun.com/thread.jsp?thread=461313&forum=9&message=2114037
    You catch an exception with code that looks like the following...
        try
          String s = null;
          int i = s.length();  // This throws an exception
        catch(NullPointerException e)
          // Do something
    You throw an exception with the following...
        if (<some condition>)
           throw new Exception("Something bad happened");

Maybe you are looking for

  • Can't open photo attachments from Gmail through Safari - Ipad2 ios7.1

    I have an ipad2, running ios7.1 If I try to open a photo attachment from www.gmail.com (in Safari, not Mail app) it causes my ipad to hang. Here's what happens for a 2mb test jpg I just sent myself: 1. Open email in Safari 2. Click on the thumbnail o

  • Can I have a common itunes library on a shared drive?

    All of my music library is stored on my Power PC G5 iMac. Itunes no longer supports PowerPC iMacs and so I can no longer sync my iPhone to my PC.  Since I cannot upgrade iTunes I can't use features such as Home Sharing or iTunes match.  Whjat I want

  • PSE6 blocks Esc key on Vista

    Hi, I have a common problem with Photoshop Elements 6 on Windows Vista (both 32bit and 64bit versions): It blocks the Esc key in all other applications! (As long as PSE6 is running, pressing the Esc key in any other windows than its own has no functi

  • No Music in MuVo V100

    Now my MuVo V00 says it has No Music when switched on even though it is full of songs. Done formatting, used Tools in the player to Error check etc several times. Still No Music !!! I know others have the same problem. But can't see any real solution

  • Apps that arbitrarily restrict which users may use the App, such as by location or carrier, may be rejected

    Hello, I have an inquiry, this section: Apps that arbitrarily restrict which users may use the App, such as by location or carrier, may be rejected We have an mBanking app to be built and the Bank is insisting on forcing a mandatory update when there