Skip to Content
author's profile photo Former Member
Former Member

How to display which exception Is Raised?

Hi

Experts.

I am trying to connect my webDynpro with oracle.

I had already included Jar at both places.

now I want to display in exception that which error is coming?

I had already written <b> ex.printStackTrace(); </b>

but it is not working.

Code Is given Below.

Connection conn=null;
		try
		{
		wdComponentAPI.getMessageManager().reportException("after 0",false);
		Class.forName("oracle.jdbc.driver.OracleDriver");
		wdComponentAPI.getMessageManager().reportException("after 1st",false);
		DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
		wdComponentAPI.getMessageManager().reportException("after 2nd",false);
		conn =DriverManager.getConnection ("jdbc:oracle:thin:@Server IP:1521:adaniinframs","scott", "tiger");
		wdComponentAPI.getMessageManager().reportException("after 3",false);
		Statement stmt=conn.createStatement(); 
		wdComponentAPI.getMessageManager().reportException("after 4",false);
		ResultSet rs=stmt.executeQuery("select ename from emp where empno=7369"); // select statment
		wdComponentAPI.getMessageManager().reportException("after 5",false);
		while(rs.next())
		{
		wdComponentAPI.getMessageManager().reportException("after 6",false);
		IPrivateDatabaseConnectView.INodeEmpElement a = wdContext.createNodeEmpElement();
		a.setEmpName(rs.getString(1));
		a.setEmpJob(rs.getString(2));
		wdContext.nodeNodeEmp().addElement(a);
		}
		}
		catch(Exception ex)
		{ 
                ex.printStackTrace();
		
		}
 
		finally
		{
		 try
		{
		conn.close(); // closing the connection
		}
		catch(Exception e)
		{  
		ex.printStackTrace();
		}
		}   

Regards

Sunny.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Sep 21, 2007 at 07:13 AM

    I don't think the user may see anything if you execute e.printStackTrace(); so what you have to do is report an exception with the text of the stack trace:

    			
    IWDMessageManager manager = wdComponentApi().getMessageManager();
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    e.printStackTrace(pw);
    String message = sw.toString();
    manager.reportException("Excepcition raised: " + message, false);
    

    With this you will report the whole stack trace. If you want to get only the cause you will have to parse the message string. e.getMessage() should do this for you but if doesn't return anything quite often.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 21, 2007 at 06:39 AM

    Hi Sunny,

    ex.printStackTrace(); will not work.

    Try this

    try

    {

    ......

    }

    catch(Exception ex)

    {

    wdComponentAPI.getMessageManager().reportException("Given Exception : "+ex.getMessage(),true);

    }

    Regards,

    Mithu

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 21, 2007 at 06:50 AM

    Hi

    better you first use the

    catch(SQLException sqe){

    wdComponentAPI.getMessageManager().reportException("SQL Exception Occured.................: "+sqe.getMessage(),true);

    System.out.println("SQLException cought........"+sqe);

    }

    Then use catch for general exception

    catch(Exception ex){.............

    ............

    }

    Regards

    Abhijith YS

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.