Solved

Why cant I catch exception

Posted on 2006-11-15
6
290 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why method in Java which is called from Runnable run() doesn't need to be 'static'? 1 24
fibonacci ten numbers 4 38
String array comparison 4 32
mysql jsp example issue 32 32
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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…

813 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now