Link to home
Start Free TrialLog in
Avatar of princehyderabad
princehyderabad

asked on

Why cant I catch exception

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
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

>>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
Avatar of princehyderabad
princehyderabad

ASKER

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.
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.
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 ?
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.