Problem in code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • madhoriya22
    Contributor
    • Jul 2007
    • 251

    #1

    Problem in code

    Hi,
    Here is the code snippet in which I have problem. When this part throws exception, request is sent to ErrorPage.jsp. Now the problem is, after forwarding the request to errorPage, the program should halt at this place and this value should not go in database...It takes hoursSpent value as 0......how should I halt flow at this point
    Code:
    double hoursSpent = 0;
            try {
                hoursSpent = Double.parseDouble(request.getParameter("hoursSpentInput"));
            }catch(NumberFormatException nfe) {
                System.out.println("not a number"+nfe);
                request.setAttribute("Message","Enter a number in 'Hours Spent'");
                request.getRequestDispatcher("ErrorPage.jsp").forward(request,response);
            }
    .......//some code here
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by madhoriya22
    Hi,
    Here is the code snippet in which I have problem. When this part throws exception, request is sent to ErrorPage.jsp. Now the problem is, after forwarding the request to errorPage, the program should halt at this place and this value should not go in database...It takes hoursSpent value as 0......how should I halt flow at this point
    Code:
    double hoursSpent = 0;
            try {
                hoursSpent = Double.parseDouble(request.getParameter("hoursSpentInput"));
            }catch(NumberFormatException nfe) {
                System.out.println("not a number"+nfe);
                request.setAttribute("Message","Enter a number in 'Hours Spent'");
                request.getRequestDispatcher("ErrorPage.jsp").forward(request,response);
            }
    .......//some code here
    After the catch clause has executed control flow continues at your
    '// some code here' where you most likely fiddle with your database again.
    Don't do that, simply return at the end of your catch clause.

    kind regards,

    Jos

    Comment

    • madhoriya22
      Contributor
      • Jul 2007
      • 251

      #3
      Originally posted by JosAH
      After the catch clause has executed control flow continues at your
      '// some code here' where you most likely fiddle with your database again.
      Don't do that, simply return at the end of your catch clause.

      kind regards,

      Jos
      Thanks Jos......Its working......Ca n you plz tell me how make code colourful while putting it in code tags :)

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by madhoriya22
        Thanks Jos......Its working......Ca n you plz tell me how make code colourful while putting it in code tags :)
        Those colour are pre-set; given the kind of code tag, the colours differ; I don't
        know the reason behind this all; here are a few examples

        [code=java]
        for (int i= 0; i < n; i++) System.out.prin tln("Hello world");
        [/code]

        [code=c]
        for (int i= 0; i < n; i++) printf("Hello world\n");
        [/code]

        [code=cpp]
        for (int i= 0; i < n; i++) cout << "Hello world" << eol;
        [/code]

        I really have no idea why those colours should be different; and please don't ask
        me about those line numbers either; I'm innocent ;-)

        kind regards,

        Jos

        Comment

        • madhoriya22
          Contributor
          • Jul 2007
          • 251

          #5
          Originally posted by JosAH
          Those colour are pre-set; given the kind of code tag, the colours differ; I don't
          know the reason behind this all; here are a few examples

          [code=java]
          for (int i= 0; i < n; i++) System.out.prin tln("Hello world");
          [/code]

          [code=c]
          for (int i= 0; i < n; i++) printf("Hello world\n");
          [/code]

          [code=cpp]
          for (int i= 0; i < n; i++) cout << "Hello world" << eol;
          [/code]



          I really have no idea why those colours should be different; and please don't ask
          me about those line numbers either; I'm innocent ;-)

          kind regards,

          Jos
          whatever u told is OK...........so rry if u find my question too silly.......
          Thanks :)

          Comment

          Working...