Catching exceptions in a declarative way....

Hi all,
I'd like to catch my exceptions as declared in my web.xml file
<error-page>
<exception-type>javax.servlet.ServletException</exception-type>
<location>/error.jsp</location>
</error-page>
the problem is that this approach doesn't work with servlets:
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
throw new javax.servlet.ServletException("errore");
this doesn't redirect to error.jsp, but it simply crashes the navigation with the stack trace.
On the other hand with JSP...
<%
throw new javax.servlet.ServletException("errore da jsp");
%>
it works. I'm using Tomcat 4.1 container.
Any help ???
Thanks
Francesco

hey,
i am not usre if u can do that.. but a better a way to handle exception and redirect to an error page is.. in every jsp/ or servlet generated page add
<%@ page errorPage="errorpage.htm"%>
So when ever an error or exception is encounterd the error page is automatically opened. in this case errorpage.htm is opened ..
hope this will help u ..

Similar Messages

  • Catching exceptions

    Maybe a stupid question but is there any common practice when it comes to handling exceptions in Java? Should I declare throws for the whole method or should I use a try-catch construction? I can see the advantage of passing exception to the calling methods but this means that many methods must be throwables or catch the exceptions so it's kind of a circle of exceptions...
    /P

    You usually don't want to do
    catch (Exception e) {}
    Somewhat less onerous is
    catch (Exception e) { //handle it }
    Normally what you'd do is define your own exception classes that extend Exception. A common approach is to use a package-based hierarchy, with specific exceptions for specific types of errors.
    // package com.mycompany.dbstuff might have these
    public class DatabaseException extends Exception { /*...*/}
    public class NoSuchTableException extends DatabaseException { /*...*/ }
    public class  LoginFailedException extends DatabaseException { /*...*/}
    // package com.mycompany.accountmanagement package may have these
    public class AccountException extends Exception {/*...*/}
    public class IllegalAccountNumberExceptoin extends AccountException {/*...*/}
    // etc.Each exception simply has constructors that call super(same args), and possibly the ability to take another Throwable as a constructor arg, which is then mapped to a member variable so you can later call getCause() or getWrappedException to see which exception led to this one.
    At any given layer, you catch exception thrown by the layers it uses, and wrap them in an exception for your current layer.
    // in the AccountClass
    public AccountInfo getAccountInfo(int acctId) throws AccountException {
        if (acctId < 0) {
            throw new IllegalAccountNumberException("No negative account numbers");
        try {
            database.login(uname, passwd);
            databse.getAccountInfo(acctId);
        catch (DatabaseException exc) {
            exc.printStackTrace();
            throw new AccountException(exc);
    }This way, the user of the accountmanagement package doesn't need to know what database package accountmanagement uses. If I call an accountmanagement method, I only have to deal with an account relatd exception. If it's IllegalAccountNumber, I can prompt the user to reenter the acct number. If it's other, I can say "Couldn't retrieve account info, please try again" or some such thing.
    And yes, I know, if the login failed, you'd want to propagate that, so the user could reenter the password. I'd make a separate AccountLoginFailedException and wrap that around the DBLoginFailed, because the user of the Account class is trying to access the account, not the database.
    Also, you often do want to print stack traces. Not in your user's face--off in a log file somehwere. If you've got exceptions that are ocurring for reasons other than user typos, you want to record as much info as you can about them.

  • Cannot catch Exception thrown by ADF (source of exception is EJB)

    Even I tried to use try catch block, it still shows unwanted error popup (showing errors) automatically generated by adf.
    I know the source of this error is EJB, I try to insert duplicate field which must be unique. So EJB throws jdbc exception.
    How can I disable popup automatically generated by ADF and show my custom error text?
            try {
                BindingContainer bindings = getBindings();
                OperationBinding operationBinding = bindings.getOperationBinding("mergeCity");
                Object result = operationBinding.execute();   
                closePopup(popEdit);
                refreshTable();
                if (!operationBinding.getErrors().isEmpty()) {           
                    return null;
            } catch (Exception e) {
                System.out.println(".......... Error..........");
            }        Edited by: user12025867 on Oct 10, 2009 11:17 AM

    For custome error handling check this thread.
    Handling custom exceptions in 11g
    if you call this on button action, do not use partialSubmit that way when the page refreshes the popup will be gone automatically.

  • Catch exceptions that occur in the constructor of a managed bean

    Hello,
    I would like to catch exceptions that might occur in the constructor of a managed bean and redirect to an error page. My beans need to get data from a database and if the database is not accessible, an error page is to tell the user "try again later". I don't want to write an action or actionListener that is invoked by a button klick on the previous page to make error handling easier, because an actionListener should not know about the next page and what data the next page will need.
    I read all postings about this topic I could find in this forum. And there are three solutions I tried:
    1) register an error-page in web.xml
    Is there an example for using this in a JSF application? It did not work. I got a "Page not found" exception
    2) Use a phase listener. But how can a phase listener do this? Is there an example? I don't think it can do it in the beforePhase method because this method is called before the constructor of the managed bean is called.
    3) Use a custom ViewHandler. This is my renderView method which creates a "Page not found" Exception.
    public void renderView(FacesContext context, UIViewRoot viewToRender) throws IOException, FacesException {
    ViewHandler outer = context.getApplication().getViewHandler();
    try {
    super.renderView(context, viewToRender);
    } catch (Exception e) {
    context.getExternalContext().redirect("/error.jspx");
    Several people write they've done it one or the other way. Please share your knowledge with us !!
    Regards,
    Mareike

    Hallo Mareike,
    Maybe I should abandon managed beans, create my own
    "unmanaged" ones inside of an action listener and put
    them somewhere my pages can find them.
    Its a pity, because I like the concept of managed
    beans.sure setter injection of JSF is fine!
    well workaround could be using <h:dataTable rendered="#bean.dbAccessible" ...>
    In your constructor you catch the exception and set
    dbAccessible = false;
    or you use error pages of webcontainer,
    but the pages couldn't contain JSF components, IMHO
    only plain JSP files.
    BTW perhaps somebody on MyFaces' list knows the solution:
    http://incubator.apache.org/myfaces/community/mailinglists.html
    Regards,
    Mareike-Matthias

  • RFC Destination Catch Exceptions

    Hello,
    I've a program with call to RFC destination 'XI' , i want to know if it is possible catch exceptions when in the other system (XI) a fault occurs, for example, the database table in which I want to insert the data is not created. Now, if this happens a dump occurs
    thanks very much,

    Hello,
    You can try this way with your RFC function module:
    CALL FUNCTION 'RFC_WRITE_FILE'
        DESTINATION FP_P_DEST
        EXPORTING
          FILE                  = L_V_NAME
          FORMAT                = L_C_BIN
          SIZE                  = L_V_SIZE
          LANGUAGE              = SY-LANGU
        IMPORTING
          SIZE                  = L_V_SIZE
        TABLES
          FILEDATA              = L_IT_FILE
        EXCEPTIONS
          SYSTEM_FAILURE        = 1  MESSAGE L_V_RFC_MESS
          COMMUNICATION_FAILURE = 2  MESSAGE L_V_RFC_MESS
          ILLEGALNAME           = 3
          OTHERS                = 6.
      CASE SY-SUBRC.
        WHEN 0.
        WHEN 1.
        WHEN 2.
        WHEN 3.
        WHEN 6.
      ENDCASE.
    The SY-SUBRC value can be captured this way. Hope this helps.
    BR,
    Suhas
    Edited by: Suhas Saha on Mar 24, 2009 4:14 PM

  • Catching exception from inherited constructor

    Hi all,
    If I'm extending a class and the constructor of the parent class throws an exception, is there any way to catch that exception in my constructor? What I would like to do is something like this.
    public class MyClass extends OtherClass {    // the constructor for OtherClass throws an exception
        public MyClass() {
            try {
                super();
            } catch (Exception e) {}
    }But of course you can't do that because super() has to be the first command in the method. Is there any other way to accomplish this? My objective is to chain this exception to a different type of exception.

    Write a factory method? For example:
    class ABCException extends Exception {}
    class XYZException extends Exception {}
    class OtherClass {
        public OtherClass()  throws ABCException {
            throw new ABCException();
    class MyClass extends OtherClass {    // the constructor for OtherClass throws an exception
        protected MyClass() throws ABCException {
           super();
        public static MyClass instance() throws XYZException {
            try {
                return new MyClass();
            } catch (ABCException e) {
                throw new XYZException();
    }

  • ABAP debugging, catch exception

    Hello, experts!
    Is there any way for catching exception from "insert <tabname> from table itab" during debugging, if there's no any exception handling in code? I want to know what is the error text to analyze it in more detail. I can't modify a program, because it has been generated automatically (it is a data loading program for BW extractor), so I need any case to insert error handling or get the error message while debug before program exit.
    Any suggestions would be appreciated.
    Thanks,
    Andrew.

    hi andrew,
    There is a catchable exception which you can try
    TRY.
         insert <tabname> from table itab
        CATCH CX_SY_ITAB_DUPLICATE_KEY.
    ENDTRY.
    There are also non-catchable exceptions which you can refer at
    ABAP Keyword Documentation

  • Doubt on try/catch exception object

    why it is not advisable to catch type exception in try catch block. Its confusing me. If i catch exception object then it will show whatever exception occured.
    btw, i was just go through duke stars how it works and saw this
    http://developers.sun.com/forums/top_10.jsp
    Congrats!

    Because there are many different kinds of Exception. If you have some specific local strategy for dealing with a particular excepion then you should be using a specific catch block.
    If you don't then you should allow the expection to end the program, and ideally you should deal with all the expceptions in one top-level handler, so you should throw, rather than catch the exceptions in your methods. Often at the outer most level of the program or thread you will actually catch Throwable (not just Exception) to deal with any unanticipated problems in a general kind of way.
    Also, you should be keeping track of what exceptions might be thrown, so that rather than using Exception in a throws clause or catch block, you should use the particular exceptions. Exceptions, generally, indicate a recoverable error that you really ought to be recovering from rather than just printing a stacktrace.
    That's why exceptions are treated differently from runtime errors.

  • Try catch exception handling

    Hi there,
    Was wondering if you could assist in me getting my head around try catch exception handling? I have this code:
    JOptionPane.showMessageDialog(null, "A subject consists of term names and definitions.\nYou should indicate the size and name of the subject");
             inputSubName = JOptionPane.showInputDialog(null, "Enter the Subject Name:");
             inputSubSize = JOptionPane.showInputDialog(null, "Enter the Subject's Term Size:");
             try {
                  size = Integer.parseInt(inputSubSize);
                  catch (NumberFormatException e) {
                            JOptionPane.showMessageDialog(null, "'" + inputSubSize + " is invalid " + " Please enter digits only");
                            inputSubSize = JOptionPane.showInputDialog(null, "Enter the Subject's Term Size:");
                            size = Integer.parseInt(inputSubSize);
             //create a new Subject object and pass in its name and size
             Subject sub = new Subject(inputSubName, size);
    ...My query is, if I catch an exception, how do I get the code to repeat the try again until the user inputs a correct data type? If the user above inputs something other than a number, it will catch it once and repeat the joptionpane inputbox, but if they do the same thing twice round - then the program bombs out. Is there a way i can get the code to retry the try until they input correctly?
    Cheers.

    eg.
    int size = 0;          
    while (true) {
         try {
              size = Integer.parseInt(inputSubSize);
              break;
         catch (NumberFormatException e) {
              JOptionPane.showMessageDialog(null, "'" + inputSubSize
                        + " is invalid " + " Please enter digits only");
              inputSubSize = JOptionPane.showInputDialog(null,
                        "Enter the Subject's Term Size:");
    }

  • Why catching Exception is bad idea??

    Hi,
    Why it is said that catching an Exception is a bad idea. Any how we get the actual cause in stackTrace of Exception object.!
    Plz help

    Catching exceptions (lowercase e) is not a bad thing. Catching Exception (uppercase E) is generally bad.
    Lowercase e exceptions refer to the entire Throwable hierarchy--everything that can be thrown and caught. Often you want to catch and handle them, or catch and wrap and rethrow them.
    Uppercase E Exception is a particular class of exception, and it's the parent class of all checked exceptions and many unchecked exceptions. When your code has catch Exception, you're saying that almost no matter what goes wrong, you want to handle it the same way. And you're also assuming that if the methods that you're calling change to throw more or fewer exceptions, your code won't need to know or care about it.
    In general you want to catch more specific subclasses of Exception, so that you can handle each one properly, and you know that your code is handling precisely the correct set of exceptions.

  • Showing message after catching Exception

    Hi,
    I'm having some troubles while trying to show a message after catching an Exception, the thing I want to do, is after they enter the values (Integer values in this case) if they didn't entered integer values shows a message that they input the wrong thing and then clear the fields.
    Here's the code:
    private void EnviarActionPerformed(java.awt.event.ActionEvent evt) throws Exception {                                      
            int dir=0, ranuras=0, mp=0, conjunto=0;
            String algoritmo=null;
            try {
                dir = Integer.parseInt(fieldDireccion.getText());       
                ranuras = Integer.parseInt(fieldRanura.getText());
                mp = Integer.parseInt(fieldMP.getText());
                conjunto = Integer.parseInt(fieldConjunto.getText());
                algoritmo = (String)(algoritmos.getSelectedItem());   
            } catch (Exception e) {
                JOptionPane.showmessageDialog(null,"Wrong values");
            }The error I have is: unreported exception java.lang.Exception; must be caught or declared to be thrown.
    Thanks in advance

    Ok well now I have another problem =S since that actionPerformed is made by netbeans itself I cant put it inside a "try".That is incorrect. You could create another method, which does all the work. Then in the original method do nothing but the try/catch and call that other method.
    But it doesn't matter because logically the code is still incorrect. Which hints by me an others have suggested.
    The method should not have a throws clause. That is the problem. If the code in the catch block can throw an exception then the solution to that is to put a try catch block around that code (inside the original catch.)

  • How to catch exception into a String variable ?

    I have a code
    catch(Exception e)
                e.printStackTrace();
                logger.error("\n Exception in method Process"+e.getMessage());
            }when i open log i find
    Exception in method Process null.
    But i get a long error message in the server console !! I think thats coming from e.printStackTrace().
    can i get the error message from e.printStackTrace() into a String variable ?
    I want the first line of that big stacktrace in a String variable.
    How ?

    A trick is to issue e.printStackTrace() against a memory-based output object.
    void      printStackTrace(PrintStream s)
             // Prints this throwable and its backtrace to the specified print stream.
    void      printStackTrace(PrintWriter s)
    //          Prints this throwable and its backtrace to the specified print writer.Edited by: BIJ001 on Oct 5, 2007 8:54 AM

  • How to catch exception while validating the username and password in hbm

    Hi,
    I do want to set the username and password dynamically in hibernate.cfg.xml
    Here below is my configuration file.
    {code<hibernate-configuration> 
    <session-factory> 
           <property name="hibernate.bytecode.use_reflection_optimizer">false</property> 
           <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property> 
           <property name="hibernate.connection.pool_size">10</property> 
           <property name="show_sql">true</property> 
           <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property> 
           <property name="hibernate.hbm2ddl.auto">update</property> 
           <property name="current_session_context_class">thread</property> 
           <property name="show_sql">true</property> 
         </session-factory> 
    </hibernate-configuration>{code}
    Also im getting that session factory object like the below code.
    public class Sessions {        private static SessionFactory sessionFactory;      private static Configuration configuration = new Configuration();        static {          try {              String userName = GuigenserviceImpl.userName;              String password = GuigenserviceImpl.password;              String hostName = GuigenserviceImpl.hostName;              String portNo = GuigenserviceImpl.portNo;              String sId = GuigenserviceImpl.sId;                  configuration                      .setProperty("hibernate.connection.username", userName);              configuration                      .setProperty("hibernate.connection.password", password);              configuration.setProperty("hibernate.connection.url",                      "jdbc:oracle:thin:@" + hostName + ":" + portNo + ":" + sId);                try {              configuration.configure("/hibernate.cfg.xml");              sessionFactory = configuration.buildSessionFactory();              GuigenserviceImpl.strAccpted = "true";              }              catch (Exception e) {                    e.printStackTrace();                  GuigenserviceImpl.strAccpted = "false";              }            }          catch (HibernateException hibernateException) {              GuigenserviceImpl.strAccpted = "false";              hibernateException.printStackTrace();          }          catch (Throwable ex) {                GuigenserviceImpl.strAccpted = "false";              ex.printStackTrace();              throw new ExceptionInInitializerError(ex);          }      }          public static SessionFactory getSessionFactory() {          return sessionFactory;      } 
    So, in this above scenario, suppose if im giving the wrong password means exception should be caught and the string variable "GuigenserviceImpl.strAccpted" should be assigned to false.
    But im getting the SQL Exception only in console like wrong username and password. And finally i couldn't able to catch the exception in Sessions class, static block.
    Anyone can help me in catching that SQL Exception in my Sessions class and i need to handle that SQL Exception in my class.
    Im getting this following exception message in my console.
      INFO: configuring from resource: /hibernate.cfg.xml  Apr 6, 2009 2:47:00 PM org.hibernate.cfg.Configuration getConfigurationInputStream  INFO: Configuration resource: /hibernate.cfg.xml  Apr 6, 2009 2:47:00 PM org.hibernate.cfg.Configuration doConfigure  INFO: Configured SessionFactory: null  Apr 6, 2009 2:47:00 PM org.hibernate.connection.DriverManagerConnectionProvider configure  INFO: Using Hibernate built-in connection pool (not for production use!)  Apr 6, 2009 2:47:00 PM org.hibernate.connection.DriverManagerConnectionProvider configure  INFO: Hibernate connection pool size: 10  Apr 6, 2009 2:47:00 PM org.hibernate.connection.DriverManagerConnectionProvider configure  INFO: autocommit mode: false  Apr 6, 2009 2:47:00 PM org.hibernate.connection.DriverManagerConnectionProvider configure  INFO: using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@192.168.1.12:1521:orcl  Apr 6, 2009 2:47:00 PM org.hibernate.connection.DriverManagerConnectionProvider configure  INFO: connection properties: {user=scott, password=****}  Apr 6, 2009 2:47:01 PM org.hibernate.cfg.SettingsFactory buildSettings  WARNING: Could not obtain connection metadata  java.sql.SQLException: ORA-01017: invalid username/password; logon denied        at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)      at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:131)      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:204)      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:406)      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399)      at oracle.jdbc.driver.T4CTTIoauthenticate.receiveOauth(T4CTTIoauthenticate.java:799)      at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:368)      at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:508)      at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:203)      at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:33)      at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:510)      at java.sql.DriverManager.getConnection(DriverManager.java:525)      at java.sql.DriverManager.getConnection(DriverManager.java:140)      at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)      at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:84)      at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2073)      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1298)      at com.beyon.ezygui.server.Sessions.<clinit>(Sessions.java:39)      at com.beyon.ezygui.server.GuigenserviceImpl.testRPC(GuigenserviceImpl.java:322)      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    Thanks in advance.
    Thanks & Regards,
    Kothandaraman N.

    Hi,
    Myself hardcoded that username and password checking like the below code.
    String name = loginData.get("userName").toString();
              String pswd = loginData.get("pswd").toString();
              String hstName = loginData.get("hName").toString();
              String prtNo = loginData.get("portNo").toString();
              String sid = loginData.get("sId").toString();
              SessionFactory sessionFactory = null;
              try {
                   if (name.trim().equals(userName) && pswd.trim().equals(password)
                             && hstName.trim().equals(hostName)
                             && prtNo.trim().equals(portNo) && sid.trim().equals(sId)) {
                        sessionFactory = Sessions.getSessionFactory();
                        strAccpted = "true";
                   } else {
                        strAccpted = "false";
              } catch (Exception e) {
                   e.printStackTrace();
                   strAccpted = "false";
              }I have my own values in string objects, then comparing that values with the values from login form. If both values are matching, then i will do configurations in hibernate.
    ResourceBundle resourceBundle = ResourceBundle
                   .getBundle("com.beyon.ezygui.server.Queries");
         public static final String connection_url = resourceBundle
                   .getString("connection.url");
         public static final String userName = resourceBundle.getString("userName");
         public static final String password = resourceBundle.getString("password");
         public static final String hostName = resourceBundle.getString("hostName");
         public static final String portNo = resourceBundle.getString("portNo");
         public static final String sId = resourceBundle.getString("sId");The above are the String objects i'm checking for the match with values from login form.
    Thanks & Regards,
    Kothandaraman N.

  • How to catch exception of JMS when call onMessage()?

    I write a consumer client implement onMessage(),
    in my main() method ...
    try {
    _adapter = new Adapter(checkConsumer,env);
    _adapter.setSelector("client = 'Receive1'");
    _adapter.start();
    System.out.println("Hello...");
    } catch(Exception e) {
    _adapter = null;
    System.out.println("Unable to start adapter: " + e.getMessage());
    _adapter.start() will call onMessage() my onMessage like this
    public void onMessage(Adapter adpt, Message message) {
    try {
    if(message instanceof TextMessage) {
    // Write the text out as read String text = ((TextMessage)message).getText();
    // Do CHECK Process adpt.demoOut("Receive CHECK Text is :" + text);
    //System.out.println("class name is " + consumerName);
    } else {
    // This is just a message (no particular type) } } catch (Exception e) {
    try {
    adpt.warn("Error outputing data: " + message.getJMSMessageID());
    } catch(Exception ignore) {
    } adpt.warn("\tError: " + e.getMessage());
    // Do some exception process }
    If the JMS Server shutdown, how can I catch the exception?

    You might want to try with exception listener that JMS specification provides.

  • How to catch exception when have max connection pool

    hi,
    i have define in oracle user that i could have max 10 sessions at the same time.
    I have jdbc datasource & connection pool defined at glassfish server(JSF application).
    now, if in application is too many queries to the database then i have error: nullpointer exception - becouse when i try to do:
    con = Database.createConnection(); - it generates nullpointer exception becouse there isn't free connection pool
    i try to catch exception like this:
    public List getrep_dws_wnioski_wstrzymane_graph() {     int i = 0;     try {     con = Database.createConnection();     ps =    (Statement) con.createStatement();     rs = ps.executeQuery("select data, klasa, ile_dni_wstrzymana, ile_wnioskow from stg1230.dwsww_wstrzymane_dws8 order by data, klasa, ile_dni_wstrzymana, ile_wnioskow");     while(rs.next()){       rep_dws_wnioski_wstrzymane_graph.add(i,new get_rep_dws_wnioski_wstrzymane_graph(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4)));       i++;     }     } catch (NamingException e) {         e.printStackTrace();     } catch (SQLException e) {         e.printStackTrace();     } catch (NullPointerException e) {         e.printStackTrace();         throw new NoConnectionException();  // catch null 1     } finally {     try {         con.close();     } catch (SQLException e) {         e.printStackTrace();     } catch (NullPointerException e) {         e.printStackTrace();         throw new NoConnectionException();  // catch null 2     }     } return rep_dws_wnioski_wstrzymane_graph; }
    but at line:
    con.close();
    i have nullpointerexception
    and
    at line
    throw new NoConnectionException(); // catch null 2
    i have: caused by exception.NoConnectionException
    what's wrong with my exception class? how to resolve it?
    public class NoConnectionException extends RuntimeException{     public NoConnectionException(String msg, Throwable cause){       super(msg, cause);     }     public NoConnectionException(){       super();     } }
    at web.xml i have defined:
    <error-page>         <exception-type>exception.NoConnectionException</exception-type>         <location>/NoConnectionExceptionPage.jsp</location>     </error-page>

    thanks,
    i did it and i have error:
    java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: ORA-02391: exceeded simultaneous SESSIONS_PER_USER limit
    at com.sun.gjc.spi.base.DataSource.getConnection(DataSource.java:115)
    at logic.Database.createConnection(Database.java:37): conn = ds.getConnection();
    public class Database {
         public static Connection createConnection() throws NamingException,
                    SQLException {
                Connection conn = null;
                try{
                    Context ctx = new InitialContext();
              if (ctx == null) {
                   throw new NamingException("No initial context");
              DataSource ds = (DataSource) ctx.lookup("jdbc/OracleReports");
              if (ds == null) {
                   throw new NamingException("No data source");
              conn = ds.getConnection();  // here's exception when max connections to database
              if (conn == null) {
                   throw new SQLException("No database connection");
                } catch (NamingException e) {
                    e.printStackTrace();
                    throw new NoConnectionException(); 
             } catch (SQLException e) {
                 e.printStackTrace();
                    throw new NoConnectionException(); 
                catch (NullPointerException e) {
                 e.printStackTrace();
                    throw new NoConnectionException();  // obsluga bledy na wypadek jesli braknie wolnych polaczen do bazy
            return conn;
    }and at my ealier code i have error:
    at logic.GetDataOracle.getrep_dws_wnioski_wstrzymane_graph(GetDataOracle.java:192)
    at line: con = Database.createConnection();
    in code:
    public List getrep_dws_wnioski_wstrzymane_graph() {
        int i = 0;
        try {
        con = Database.createConnection();
        ps =    (Statement) con.createStatement();
        rs = ps.executeQuery("select data, klasa, ile_dni_wstrzymana, ile_wnioskow from stg1230.dwsww_wstrzymane_dws8 order by data, klasa, ile_dni_wstrzymana, ile_wnioskow");
        while(rs.next()){
          rep_dws_wnioski_wstrzymane_graph.add(i,new get_rep_dws_wnioski_wstrzymane_graph(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4)));
          i++;
        } catch (NamingException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (NullPointerException e) {
            e.printStackTrace();
            throw new NoConnectionException();
        } finally {
        try {
            if(con != null)
            con.close();
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (NullPointerException e) {
            e.printStackTrace();
            throw new NoConnectionException(); 
    return rep_dws_wnioski_wstrzymane_graph;
    }so what's wrong?
    i have limit max sessions 10 at oracle so i set at my connection pool 5 connections as max. But when i get max 5 sesssins and try to execute next query then i can't catch exception..

Maybe you are looking for

  • Bizzar JVM crash on dual Xeon EMT64 machine

    I am posting this one here to see if anyone else has the same or similar experience. I have an Java application running on a Windows Server 2003 SP1 OS with dual Xeon EMT64. It is running on Sun's JDK 1.5 Update 3, and every couple of hours the JVM i

  • In design view the cursor doesn't display correctly with text how to fix

    When working in the design view in a text block the cursor shows in one spot but the code view show it is over a few characters so you have a real hard time editing text in that mode.  How do you fix this.  I have had this issue in several version of

  • My music from sdcard disapeared from player,

    hi, i had a z10, and used to listen to my music with the player (when the z10 recognized my 64g sdcard!). I got a passport, and since, i can't bind the music from link or in the music player to the music folder of my sdcard, even when it's recognized

  • Need help with an error 1009

    so i am a highschool student and i am working on a project in game design and so im working on it then this 1009 ******* comes up and i have been working on getting rid of this for a few days with no luck or only bad luck. so i asked my teacher he co

  • Recover bios lenovo G500 black screen

    hi after disabling intel graphic from the advanced option in bios of G500 the screen is black i tried other monitors but it doesnt show anything i remoevd battery of bios , RAM, Hard but still nothing even after removing RAM the CPU workd but the scr