×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    19

    Confused with exception handling

    Hi, My application keeps on restarting or sometimes will give not enough memory which i suspect it's due to the memory leak caused by inproper handling of exeptions. I have read the APIs but however I am still confused about how it really works and couldn't solve my problem. Below is the code which runs, when the application tries to save an image, and it is suspect the error comes from there. Can anyone help to point out the error? Thank you


    if( iFormat == CCamera::EFormatExif )
    {
    TInt fErr = iFile.Replace( *aFs, *aNewFilePathAndName, EFileWrite );

    if (fErr == KErrNone)
    {
    iState = EConvertingImage; // no need for actual conversion step

    CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
    TBuf<80> text;

    text.Append(_L("Longitude: "));
    text.AppendNum(iLongitude);
    text.Append(_L("Latitude: "));
    text.AppendNum(iLatitude);
    informationNote->ExecuteLD(text);

    HBufC8* newExif = NULL;//1
    CExifModify* modify =NULL;

    TPtr8 tprBuff = iImageExif->Des();

    // NewL will leave with KErrCorrupt if EXIF info not valid
    TRAPD(error, modify = CExifModify::NewL( tprBuff));

    if(error == KErrCorrupt)
    {
    //modify = CExifModify::NewL( tprBuff, CExifModify::ECreate);
    //createNew = ETrue;
    }

    CleanupStack::PushL(modify);

    modify->SetImageDescriptionL( _L8("TestS60App") );
    modify->SetMakeL( _L8("Nokia S60") );

    // WriteDataL will leave with KErrNotReady if mandatory tags not present
    TRAP(error, newExif = modify->WriteDataL(tprBuff));

    if(error!=KErrNotReady)
    User::LeaveIfError(error);

    if(error == KErrNone)
    {
    iFile.Write( *newExif, iStatus );
    }

    // Pop loaded resources from the cleanup stack
    CleanupStack::PopAndDestroy(1); //1 modify
    SetActive();
    return;
    }
    }

  2. #2
    Super Contributor
    Join Date
    Jan 2008
    Location
    Bangalore, India
    Posts
    777

    Re: Confused with exception handling

    have u poped and destroyed both object properly,
    HBufC8* newExif;
    CExifModify* modify;

    i think u have done it only for one
    "// Pop loaded resources from the cleanup stack
    CleanupStack::PopAndDestroy(1); //1 modify "
    do for both..
    Regards
    $-Nitesh-$

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    19

    Re: Confused with exception handling

    if(error == KErrNone)
    {

    CleanupStack::PushL(newExif);//newly added code
    iFile.Write( *newExif, iStatus );
    CleanupStack::PopAndDestroy(newExif);//newly added code

    }

    // Pop loaded resources from the cleanup stack
    CleanupStack::PopAndDestroy(1); //1 modify
    SetActive();
    return;

    Thank for the help! However, I am still not sure where to do the pushing and popping. I only understand that I should do a push before a smthing that leaves and a pop after it. I am also not sure for my code, should i use PopAndDestroy or just pop.

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,674

    Re: Confused with exception handling

    Pop removes an item from the cleanup stack
    PopAndDestroy removes and releases (deletes, closes - depending on the class and the Push you have used).

    So
    Code:
    CMyClass *localvariable=CMyClass::NewL(something);
    CleanupStack::PushL(localvariable);
    
    ... do something ...
    
    CleanupStack::PopAndDestroy(); // localvariable
    is the same as
    Code:
    CMyClass *localvariable=CMyClass::NewL(something);
    CleanupStack::PushL(localvariable);
    
    ... do something ...
    
    CleanupStack::Pop(); // localvariable
    delete localvariable;
    PopAndDestroy is a shortcut for pop-ing and delete/close/etc.-ing in one step.

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    19

    Re: Confused with exception handling

    Sorry, I still do not understand how to implement them. Is "iFile.Write( *newExif, iStatus );" a function which leaves or do I have to specify it?

    If it is a function that leave, is this how I should put my push and pop?

    Code:
    TRAP(error, newExif = modify->WriteDataL(tprBuff) );
    if( error != KErrNotReady )
    {
       User::LeaveIfError( error );
    }
    CleanupStack::PushL(newExif);    
    	            
    if( error == KErrNone )
    {
       // Write valid EXIF structure
       iFile.Write( *newExif, iStatus );
    }
    else
    {
    // Do nothing if EXIF structure is incomplete
    }
    CleanupStack::PopAndDestroy( newExif );

  6. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    19

    Re: Confused with exception handling

    Basically, what I did is to modify the following part of code (taken from a camera example) so that the image saved will be inserted with my own exif information.

    Code:
    if( iFormat == CCamera::EFormatExif )
    {        
       TInt fErr = iFile.Replace( *aFs, *aNewFilePathAndName, FileWrite );
       if (fErr == KErrNone)
       {
       iState = EConvertingImage; 	 
       iFile.Write( *iImageExif, iStatus );
       
       SetActive();
       return;
       }
    }
    so this code becomes. However, I am having problems with the exception handling. Can someone please enlighten me? Thank you.

    Code:
    if( iFormat == CCamera::EFormatExif )
    {        
       TInt fErr = iFile.Replace( *aFs, *aNewFilePathAndName, EFileWrite );
       if (fErr == KErrNone)
       {
          iState = EConvertingImage; 	              
    
          TPtr8 tprBuff = iImageExif->Des();
    	            
          CExifModify* modify =NULL;
    	            
          // Will leave with KErrCorrupt if EXIF info not valid
          TRAPD(error, modify = CExifModify::NewL( tprBuff));
          if(error == KErrCorrupt)
          {
        //modify = CExifModify::NewL( tprBuff,CExifModify::ECreate );
        //createNew = ETrue;
          }
    
          CleanupStack::PushL( modify );
    	          
          modify->SetImageDescriptionL( _L8("TestS60App") );
          modify->SetMakeL( _L8("Nokia S60") );
    	            
          HBufC8* newExif = NULL;
    	            
          // WriteDataL will leave with KErrNotReady if 
          // mandatory tags not present      
          TRAP(error, newExif = modify->WriteDataL(tprBuff) );
          if( error != KErrNotReady )
          {
    	 User::LeaveIfError( error );
          }
          CleanupStack::PushL(newExif);    
    	            
          if( error == KErrNone )
          {
    	  // Write valid EXIF structure
    	  iFile.Write( *newExif, iStatus );
          }
          else
          {
    	   // Do nothing if EXIF structure is incomplete
          }
          CleanupStack::PopAndDestroy( newExif );
          CleanupStack::PopAndDestroy( modify ); 
    			
          SetActive();
          return;
       }//end of if kerrNone
    }//end of if iFormat is CCamera::EFormatExif

Similar Threads

  1. s60 3rd ed emulator crash
    By Kimau in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2008-06-18, 22:12
  2. VS.Net 2003 Carbide 2.01 and epoc32.exe
    By ValentinK in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 2
    Last Post: 2007-01-12, 12:31
  3. Exception handling
    By srkreddy999 in forum Symbian User Interface
    Replies: 1
    Last Post: 2006-01-12, 13:14
  4. DivideByZero exception handling
    By alexdoor73 in forum Symbian
    Replies: 1
    Last Post: 2003-10-01, 15:03
  5. can not successfully link any sample using .NET
    By lobotomat in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2002-08-20, 00:29

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×