Solved

Why cant I catch exception

Posted on 2006-11-15
6
286 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
What is the latest versions eclipse neon 2 123
Java and GPO 11 47
recursion example 16 71
micro services spring boot application error 3 43
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

744 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

12 Experts available now in Live!

Get 1:1 Help Now