×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Regular Contributor
    Join Date
    Jan 2010
    Posts
    69

    Problem: User::LeaveIfError(iConnection.Start(connectPref));

    All
    some times, my app cresh when run "User::LeaveIfError(iConnection.Start(connectPref));" the code as follow

    User::LeaveIfError(iSocketServ.Connect());
    User::LeaveIfError(iConnection.Open(iSocketServ));
    TCommDbConnPref connectPref;
    connectPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
    connectPref.SetIapId(iSelectedIap);
    User::LeaveIfError(iConnection.Start(connectPref));

    iSocketServ.Connect(), iConnection.Open(iSocketServ) have not leave,and iSelectedIap is exist (a function to find fixed iap, if not found in phone,then creat it) .
    is there some other method cause Leave when run User::LeaveIfError(iConnection.Start(connectPref))?
    by the way, it happend in my N95(8G), on other N81, even if it need long time to connect network, it have not raise Leave run it?
    the network is not cmwap or cmnet, it is cmmm, it is unstabitily refer to cmwap(cmnet), but it alway ok, and n81 is ok to use it

  2. #2
    Registered User
    Join Date
    Feb 2007
    Location
    India
    Posts
    1,128

    Re: Problem: User::LeaveIfError(iConnection.Start(connectPref));

    HI Julio,

    Check You leave value...iConnection.Start(connectPref); ?? what is ERROR CODE??

  3. #3
    Regular Contributor
    Join Date
    Jan 2010
    Posts
    69

    Re: Problem: User::LeaveIfError(iConnection.Start(connectPref));

    Quote Originally Posted by kis_spn View Post
    HI Julio,

    Check You leave value...iConnection.Start(connectPref); ?? what is ERROR CODE??
    Yes,as it happend sometimes,so i want to imitate the leave, but fails
    User::LeaveIfError(iSocketServ.Connect());
    User::LeaveIfError(iConnection.Open(iSocketServ));
    TCommDbConnPref connectPref;
    connectPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
    connectPref.SetIapId(200); //iSelectedIap);
    TRAPD(result,iConnection.Start(connectPref));
    LOG_FMT(_L("Connection Start state = %d"),result);
    if (KErrNone != result)
    {
    LOG(_L("connection timeout"));
    iObserver->ClientEvent(msg->Des());
    }

    the value of result is 0, i am worry about it could not TRAP the result when "iConnection.Start(connectPref))" really leave.
    if it can trap the ERROR CODE(cause by iConnection.Start(connectPref))" ), i can exit my program.
    can i TRAPD this error by this way?
    thank you!

  4. #4
    Registered User
    Join Date
    Feb 2007
    Location
    India
    Posts
    1,128

    Re: Problem: User::LeaveIfError(iConnection.Start(connectPref));


  5. #5
    Nokia Developer Champion
    Join Date
    Dec 2008
    Posts
    2,357

    Re: Problem: User::LeaveIfError(iConnection.Start(connectPref));

    Instal the ErrRd.SIS as mentioned in Post #4 and then run the app, it will pop you up with some error message.

  6. #6
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: Problem: User::LeaveIfError(iConnection.Start(connectPref));

    iConnection.Start() does not leave, if a function leaves it has a trailing L in its name.
    It returns an error code, just get the return code as you would for any function returning a value and pass that to LOG_FMT as you are already trying to do.

  7. #7
    Regular Contributor
    Join Date
    Jan 2010
    Posts
    69

    Re: Problem: User::LeaveIfError(iConnection.Start(connectPref));

    Quote Originally Posted by hotcheese View Post
    iConnection.Start() does not leave, if a function leaves it has a trailing L in its name.
    It returns an error code, just get the return code as you would for any function returning a value and pass that to LOG_FMT as you are already trying to do.
    hello:
    In many filed, We use "User::LeaveIfError()" to exit app with no notice( eg User::LeaveIfError(iSocketServ.Connect()) it may a panic or leave, if we want a notice,
    we should useTRAPD( eg TRAPD(err,iConnection.Start(connectPref)); if(err!=KErrNone) { do error handle;} ). Generally, TRAPD could do nothing when panic grow,
    I know this case for example call iAO->Do() when iAO is NULL, User::LeaveIfError(iSocketServ.Connect()); the iSocketServ.connect() alse have no trailing L, when the app is exit cause by it
    is it a leave(that i can TRAPD), or a pinac. now i want to handle in my way(delay to exit app or kill this thread) no need UseLeave with no notic, how could i do to TRAP this error?
    I am worry about it is no effect to TRAP this error,

  8. #8
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,751

    Re: Problem: User::LeaveIfError(iConnection.Start(connectPref));

    Here are some clues:
    TRAPD=try+catch
    Leave=throw
    Start does not leave, it returns an error code.

    TRAPD is a macro and you can find its definition in the SDK.
    Pseudo-code:
    TRAPD(err, SomethingL()); becomes
    Code:
    TInt err=0;
    try
    {
        SomethingL();
    }
    catch(TInt ex)
    {
        err=ex;
    }
    while User::LeaveIfError(x) is something like
    Code:
    if(x<0) throw x;
    return x;
    Now TRAPD(err,User::LeaveIfError(iConnection.Start()); could be written as
    Code:
    TInt err=iConnection.Start();
    at the end, in both cases you have to check err, and that is all. It is KErrNone (0) if everything is fine. It is KErrCancel if user selects cancel. It is KErrCouldNotConnect (perhaps) if it can not connect. It is KErrPermissionDenied if NetworkServices capability is missing. And it might be something else too, like KErrBusy (if you have many other requests pending on the same RSocketServ, so it rarely happens with RConnection::Start in practice).

  9. #9
    Nokia Developer Moderator
    Join Date
    Sep 2004
    Location
    Tampere, Finland
    Posts
    11,359

    Re: Problem: User::LeaveIfError(iConnection.Start(connectPref));

    You use TRAP to capture leaves, not errors.

    Since RConnection::Start returns an error code, all you have to do is:

    Code:
    TInt errorCode = iConnection.Start(connectPref);
    if(errorCode != KErrNone)
    {
         RDebug::Print(_L(" Connection start failed  with error: %d", errorCode));
         User::Leave(errorCode);
    }
    while the following code does the same thing, minus the logging:

    Code:
    User::LeaveIfError(iConnection.Start(connectPref));
    There's nothing to trap. Or if you really want to write some really strange code then try this:

    Code:
    TRAPD(error, User::LeaveIfError(iConnection.Start(connectPref)));
    if(error!= KErrNone)
    {
         RDebug::Print(_L(" Connection start failed  with error: %d", error));
         User::Leave(error);
    }
    -- Lucian

    If you are not yet a DVLUP member it is time to correct that mistake :) Click here to join: http://www.dvlup.com/lucian/Invite

Similar Threads

  1. how to get the iConnection.Start(prefs) event?
    By lmyuanhang in forum Symbian
    Replies: 1
    Last Post: 2010-03-31, 05:00
  2. Replies: 5
    Last Post: 2008-11-11, 08:32
  3. iConnection.Start(prefs) access denied
    By rakesh.jaiswal in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2005-04-04, 10:59

Posting Permissions

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