Where should I close my cursor when an Exception arise ??

Hi all,
My program has many procedures and functions. Among them I have a main procedure where everything starts, and everything should ends.
My main procedure has also an exepction part with a when others clause to log any unexpected exception.
I have another procedure (let's call it P1), that is called from my main procedure, where i use an explicit cursor in a bulk collect. While i process all my cursor data, i call many others procedures and functions, and they might call many others also.
In P1 i also have an Exception part, where i have a When others clause (in case an unexpected execption arise in any other procedure or function) where I close my cursor and raise the exception to my main procedure.
My problem is that when an exception is raised to my main program (from P1), i lose the true error line number of the exception. I am using this function to get my error trace: dbms_utility.format_error_backtrace.
I did a test, and I commented the exception part in P1, so that all exceptions goes straighly to my main procedure, and the result it was that I could see the true error line again.
So my problem was the raise statement in the when others inside of P1.
The thing is that I need to close my cursor in case of any exception, but if I do it in the when others, I will lose the true error line number of the expection.
By the way I can’t declare my cursor variable as global, so that I can remove the exception part in P1, and close my cursor in my main procedure.
I will really apreciate your help.
(I am using Oracle Databas 11g).

919448 wrote:
The cursor i am using is a ref cursor, so i have to close it explicitly as per you said.
The thing is that i don't want to lose my error line number when i raise the exception :(
Too bad if i can't get both things to be done.
I was thinking of creating my cursor variable in the main procedure, and send it as an input parameter to P1, so that i can close the cursor from the main, in case a exceptionExactly why does the error backtrace not work? Have you tried recording it earlier rather than later? E.g.
SQL> create or replace type TStackStruct is object(
  2          time timestamp,                      
  3          sqlCode integer,                     
  4          stack   varchar2(32767)              
  5  );                                           
  6  /                                            
Type created.
SQL> create or replace type TStackArray is table of TStackStruct;
  2  /                                                          
Type created.
SQL> create or replace package SessionData is
  2          stackArray      TStackArray;   
  3          procedure AddException( errCode integer );
  4          function Stack return TStackArray;       
  5  end;                                             
  6  /                                                
Package created.
SQL> create or replace package body SessionData as
  2                                              
  3          procedure AddException( errCode integer )  is
  4          begin                                       
  5                  if stackArray is null then          
  6                          stackArray := new TStackArray();
  7                  end if;                                
  8                                                         
  9                  stackArray.Extend(1);                  
10                  stackArray( stackArray.Count ) := new TStackStruct( SysTimestamp, errCode, dbms_utility.format_error_backtrace );
11          end;                                                                                                                    
12                                                                                                                                  
13          function Stack return TStackArray is                                                                                    
14          begin                                                                                                                   
15                  return( stackArray );                                                                                           
16          end;                                                                                                                    
17                                                                                                                                  
18  end;                                                                                                                            
19  /                                                                                                                               
Package body created.
SQL> create or replace procedure ProcA is
  2  begin
  3          raise NO_DATA_FOUND;    --// ProcA line 3 : error source
  4  exception when OTHERS then
  5          SessionData.AddException( SQLCODE );
  6          raise;
  7  end;
  8  /
Procedure created.
SQL> create or replace procedure ProcB is
  2  begin
  3          ProcA;
  4  exception when OTHERS then
  5          SessionData.AddException( SQLCODE );
  6          raise;
  7  end;
  8  /
Procedure created.
SQL>
SQL> begin
  2          ProcB;
  3  exception when OTHERS then
  4          SessionData.AddException( SQLCODE );
  5          raise;
  6  end;
  7  /
begin
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 5
SQL>
SQL> select * from TABLE(SessionData.Stack);
TIME                              SQLCODE STACK
08/MAR/12 18:38:09.425072             100 ORA-06512: at "BILLY.PROCA", line 3
08/MAR/12 18:38:09.425384             100 ORA-06512: at "BILLY.PROCA", line 6
                                          ORA-06512: at "BILLY.PROCB", line 3
08/MAR/12 18:38:09.425463             100 ORA-06512: at "BILLY.PROCB", line 6
                                          ORA-06512: at line 2

Similar Messages

  • Where should i wear my nano when in fitness mode?

    i used nike fitness last ngiht clipped to my shorts but it seemed to give an inacurrate distace. where should i be wearing it?

    i used nike fitness last ngiht clipped to my shorts but it seemed to give an inacurrate distace. where should i be wearing it?

  • How to close open cursors in a forms app

    All,
    I'm not a forms developer. I'm a database administrator so I'm asking this question from that perspective. I know nothing about forms development.
    We have several forms applications that appear to hold many SELECT cursors open when they run. I've asked my forms developers about this and they are giving me the idea that they don't have much control over this. I have no idea myself so I'm asking here.
    When one issues selects from a form, do those selects remain as open cursors while the form runs? Is it possible to close those select cursors from within the form so that the application does not keep so many cursors open simultaneously?
    I am typically seeing a forms application with 70-100 open cursors. And we have hundreds of end users each running the forms application which is causing a lot of problems with the sheer number of open cursors.
    I've already bumped the database OPEN_CURSORS parameter but it's my feeling that developers should be doing a better job of closing cursors from within the form.
    Can anyone give me some guidance here or point me to some documents that describe how to reduce the number of open cursors to the database from a forms app?
    Thanks,

    There are several ways Forms use cursors. In the standard default method, users enter a query where condition and then execute the query. This process opens a cursor on the server, and the form fetches a few (20 or so) rows and displays on the screen (in a base-table "block"). If the user scrolls down, more rows are fetched from the cursor. This can go on and on if the user keeps scrolling down through the data. I am not sure when the cursor gets closed -- there is no Forms command to close this one. Only closing the form, or else re-executing the query process would close such a cursor.
    In the PL/SQL code, where the developer has control, a cursor can be opened, rows fetched, and then closed. This can be done either with Open-Fetch-Close or in a For... Loop. The developer can explicitly close this cursor, or PL/SQL theoretically closes the cursor when the block of code is exited.
    There is of course the SQL Select into, but that only works in PL/SQL for single-row selects. I doubt this is a major problem.
    And finally, there are the record groups, where Forms runs the select to draw all the data into an array in the form. These should be closed automatically, I believe.
    Now... if you can determine which tables the cursors are remaining open, maybe your developers can zero in on the forms, and maybe clean up some things. However, I am doubtful much can be done. It seems to me that if the open cursors are causing some database sluggishness, then maybe adding more memory on the server is the best option.

  • Where should itunes folder be located windows 8

    where should my itunes folder be when i installed on pc i put it here Windows 8: C:\Users\username\My Music\iTunes\  put i found another itunes folder in mydoculments folder and it says that is where it was put after itunes 11.  so which one do i need

    See: http://support.apple.com/kb/ht1391
    It may be that you are seeing an alternate path provided for backwards compatibility and there is really only one iTunes folder. The one you should be using is C:\Users\<User>\Music\iTunes. The "My" or "User's" bit gets added on to the name of the Music folder depending on which user you are logged in as, but in reality the folder is simply called Music. Windows Vista and susequent versions attempt to support references to ...<Profile Folder>\My Documents\My Music and redirect to ...<Profile Folder>\Music.
    tt2

  • Where should i include my conn.close() command

    Hi,
    My code frequently fetches data from database, so i created a class like this
    public class ConnectToDatabase { /*            public ConnectToDatabase()                 {                                 Connection conn;                 } */ public ResultSet selectS(String userQuery) throws Exception { String userName = "root"; String userPassword = "gal"; String databaseUrl = "jdbc:mysql://localhost:3306/test"; Class.forName ("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection (databaseUrl, userName, userPassword); String query = userQuery; Statement S=conn.createStatement(); ResultSet RS=S.executeQuery(query);                                 //conn.close;    ( "a" ) return RS;                                 //conn.close;    (" b ") } /*              public void closeConnection()                 {                                 conn.close;                 } */ }
    and from the main code i make call as given below (it works fine)
    ConnectToDatabase CTD=new ConnectToDatabase(); ResultSet result=CTD.selectS(String userQuery); //CTD.closeConnection();
    Now my problem is
    1) If try to give "conn.close()" before "return RS;"(marked by "a") It will show error (RS cannot be fetched after closing connectio)
    2) If write conn.close after return it wont be executed (ofcourse - unreachable statement) ( "b" )
    3) If use "CTD.closeConnection();" it gives errror saying that "cannot find conn(in closeConnection()) " i dont know why constructor is not loaded.(rest of commented lines when uncommented)
    Where should i use conn.close statement? I dont want any change in my return type or parameters...

    I used like this
    public class ConnectToDatabase
       Connection conn;
       public ResultSet selectS(String userQuery,String[] userInput,int inputNumber )
           //code to select
       public void closeC()
           conn.close();
    }and from main class
    ConncetToDatabase CTD=new ConnectToDatabase();
    ResultSet RS=CTD.selectS(x,y,z) ;
    CTD.closeC();

  • My iPhone camera will not open up. When I press on the icon it open and closes quickly. When I open it from my home screen it reboots my phone. What should I do?

    My iPhone camera will not open up. When I press on the icon it open and closes quickly. When I open it from my home screen it reboots my phone. What should I do?

    Tried that and it still isn't working. Not sure if it's software thing but I just noticed when I swipe up my control center the flashlight option is not available as well. I'm not sure why this is. I have a 5s with the newest software. That's for the suggestion

  • TS3297 @My account when billing in new card,they told me to contact ITunes store support to complete my transaction...where should I go?

    @My account when billing in new card,they told me to contact ITunes store support to complete my transaction...where should I go?

    Click here and request assistance.
    (79195)

  • TROUBLE MOVING CONTACTS FROM ONE GROUP , TO OTHER (APPLE ADDRESS BOOK) WHEN I TRY TO DRAG IT WON'T STAY . WHERE SHOULD I BE , AND HOW DO I DRAG ???? AND RELEASE

    TROUBLE MOVING CONTACTS FROM ONE GROUP , , TO OTHER (APPLE ADDRESS BOOK) WHEN I TRY TO DRAG IT WON'T STAY . WHERE SHOULD I BE , AND HOW DO I DRAG ???? AND RELEASE   AB

    I have many different mailaccounts and different groups of contacts on my ipad and iphone. Sometimes i made the mistake when i create a new account linking it with the standard account. How it is possible to move one account to an other group?

  • HT4059 when i click my iphone books tab dsnt appear on the resulting window so where should i drag my pdfs

    when i click my iphone books tab dsnt appear on the resulting window so where should i drag my pdfs

    What happens if you go to iTunes > File > Devices, do you get the option to Sync iPhone?
    You could try a reinstall of iTunes. OS X Yosemite: Reinstall apps that came with your Mac

  • MenuBar should not close when menuitem is selected

    MenuBar should not close when menuitem is selected so that user can check multiple menu items

    PopUp a List instead.
    Alex Harui
    Flex SDK Developer
    Adobe Systems Inc.
    Blog: http://blogs.adobe.com/aharui

  • You but should be when I have scurrty cood can not close the I phone should be when I need close phone I but scurty cood for can I close my phone it is biter for can't any one close phone directly  When I have program for fined my I phone when any one clo

    you but should be when I have scurrty cood can not close the I phone should be when I need close phone I but scurty cood for can I close my phone it is biter for can't any one close phone directly
    When I have program for fined my I phone when any one close phone no have internet can't find my phone agine

    It is biter for any thief take my phone can't close my phone when he close my phone can't found agine because I open 3G when thife close my phone it is finsh can't yousing program for find my I phone
    Plz back to think my point it is biter for can't lose phone
    Should be when I need close the iPhone when I have scurty cood should be when I close I but scurty cood agine
    Thank  you very mutsh

  • HT1491 I bought a ringtone and when I sync my Iphone to my computer, it's not there enymore, Where should I look?

    I bought a ringtone and when I sync my Iphone to the computer it desapear.. can't see the ringtone in my phone no more..where should I look?

    You look at when you can sect various ringtones for an alert or similar. Like if you go to a contact and tap on edit and then go to ringtone you should see the added tone as a selection

  • EntityManagerFactory - when should be close ?

    Hi ,
    I am using TOPLINK and getting after some time of application running an Error :
    Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.DatabaseException
    Internal Exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
    This is probably because I am closing EntityManagerFactory, and than calling it again with out checking (emf.isOpen())...
    OK my fault, but the main question is , should I close EntityManagerFactory after done job, and than every time when I need it again opening ?
    Or leave open as a private Attribute ? :
    private EntityManagerFactory emf = Persistence.createEntityManagerFactory("TestModel", new java.util.HashMap<String, String>());thank you, greetings
    andrzej
    Edited by: andrzej76 on Aug 30, 2010 1:30 AM

    Hi ,
    I am using TOPLINK and getting after some time of application running an Error :
    Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.DatabaseException
    Internal Exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
    This is probably because I am closing EntityManagerFactory, and than calling it again with out checking (emf.isOpen())...
    OK my fault, but the main question is , should I close EntityManagerFactory after done job, and than every time when I need it again opening ?
    Or leave open as a private Attribute ? :
    private EntityManagerFactory emf = Persistence.createEntityManagerFactory("TestModel", new java.util.HashMap<String, String>());thank you, greetings
    andrzej
    Edited by: andrzej76 on Aug 30, 2010 1:30 AM

  • Where can close the objects when i am using prepareStatement

    hi,
    where can close the objects when i am using prepareStatement
    the following is code i am using.
    Connection connection;
         PreparedStatement prepare;
         JTextField tfStateNameEng;
         JTextField tfStateNameKan;
         JButton save;
         public DynamicSQL(){
    try{
         Class.forName("com.mysql.jdbc.Driver");
    connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/kantest","gk","gk");
         String sql ="insert into daya (Name,Name_KAN) values (?,?)";
         prepare = connection.prepareStatement(sql);
    }catch(Exception e){System.out.println(e);}
         tfStateNameEng = new JTextField(20);
         tfStateNameKan = new JTextField(20);
         save = new JButton("save");
         save.addActionListener(this);
         this.getContentPane().add(tfStateNameEng,"North");
         this.getContentPane().add(tfStateNameKan,"Center");
         this.getContentPane().add(save,"South");
         pack();
         setVisible(true);
         setDefaultCloseOperation(EXIT_ON_CLOSE);
    public void actionPerformed(ActionEvent ae){
         try{
              prepare.clearParameters();
              prepare.setString(1,tfStateNameEng.getText());
              prepare.setString(2,tfStateNameKan.getText());
              prepare.executeUpdate();
              }catch(Exception e){System.out.println(e);}
    /*try{
              //     connection.close(); // if going to close object here then it won't work
                   //prepare.close();//next time.
              }catch(Exception e){} */
         public static void main(String args[]){
              new DynamicSQL();
    thanks
    daya

    hello,
    ok.
    thanks
    daya

  • Illustrator CS6: Missing small pixels box that should follow the cursor when creating objects

    Somehow I've managed to disable a feature in Illustrator CS6 that does two things: 1) it causes a small box to follow the cursor when I'm drawing an object 2) the light green lines or x's are gone now, too. How can I get them back? Are they only visible under certain circumstances?  Thanks!

    SmartGuides is not simply "on" or "off". It has settings for what displays. Check your SmartGuides preferences.
    JET

Maybe you are looking for