Solved

Why cant I catch exception

Posted on 2006-11-15
6
292 Views
Last Modified: 2010-03-31
hi,

I'm using my java code as:

..
String operation = "Failed";
 public ActionForward execute(....)    throws IOException, ServletException, SQLException  {
...
try
{
  ..
  if <condition>
  { ..
   ..
  CallableStatement cs2 = conn.prepareCall("{call National (?) }");   ------> error occured here
  ....
  operation = "Passed";
  }
  else
  { ..}
}
catch (SQLException ee)
        { .. }
catch (Exception e)
        { ..}
..
}

I can see the error occured while runing that DB function. But GUI didnt showed any exception msg or so. How can I show exception on GUI .

thx
PH
0
Comment
Question by:princehyderabad
6 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 17951004
>>How can I show exception on GUI .

You don't want to be showing exceptions in the GUI. They are only of interest to you, not the user
0
 

Author Comment

by:princehyderabad
ID: 17951093
okay even then when exception occured it should not execute succesufuly. how come even after exception at preparecall(DB function) still it run rest of code.
0
 
LVL 6

Expert Comment

by:SamsonChung
ID: 17951128
princehyderabad,

to show the error on your GUI,

within the catch block on your (SQLExecpetion ee)

set some caption or text box to ee

that will display your error on gui.

To answer you 2nd question,

that's what we call a try catch block.

try it, if it works greate, else, continue.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:princehyderabad
ID: 17951159
I'm already throwing on system if any error: here is full catch code:
catch (SQLException ee)
        {          
            String msg = "DB Exception:" + ee;
            log.error(msg, ee);
            System.out.println("SQL Exception: "+ee);
        }
        catch (Exception e)
        {          
            String msg = "General Exception:" + e;
            log.error(msg, e);
            System.out.println("General Exception: "+e);
        }

It is also showing on log those error. But my concern is how come the page executing even after error. Action class should break and shoudl casue error rite ?
0
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 17951236
u need to rethrow the exceptions

catch (SQLException ee)
        {          
            String msg = "DB Exception:" + ee;
            log.error(msg, ee);
            System.out.println("SQL Exception: "+ee);
            throw new ServletException("database error", ee);
        }
        catch (Exception e)
        {          
            String msg = "General Exception:" + e;
            log.error(msg, e);
            System.out.println("General Exception: "+e);
            throw new ServletException("general error", e);
        }
0
 
LVL 6

Expert Comment

by:SamsonChung
ID: 17951293
Hell no.

well, unless you do it like object's suggestions, throw that exception.

but it should be caught and handle too.

you don't want a faulty system like that.

that's why I love try catch blocks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jdbc error in jsp application 20 71
type mismatch (Object[] to double[] 4 41
Bot application - advice 3 58
Need Help! Getting a syntax error and don't understand why 3 38
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question