Solved

Why cant I catch exception

Posted on 2006-11-15
6
293 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Independent Software Vendors: 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
hibernate example issues from command prompt 10 85
Chrome and Firefox Java 5 88
Is Applet the way to go for my drag and drop system? 8 51
glassfish admin console 1 52
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

739 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