Throw is not supported in event handler :(



  • I had used exceptional handling in event handler. When exceptions occurs the program gets crashed with message qt does not support throw in event handler. so is there any way to manage this with using throw statement.
    @void Application::Validate()
    {
    //Do validation here.
    try
    {
    if(!QRegExp("[a-zA-Z]{2,}").exactMatch(this->fname))
    {
    throw FNAME;
    }
    else if(!this->mname.isEmpty() && !QRegExp("[a-zA-Z]{2,}").exactMatch(this->fname))
    {
    throw MNAME;
    }
    else if(!QRegExp("[a-zA-Z]{2,}").exactMatch(this->lname))
    {
    throw LNAME;
    }
    else if(!QRegExp("[a-zA-Z0-9]{2,}").exactMatch(this->passportNo))
    {
    throw PASSPORTNO;
    }
    else if(!QRegExp("[a-zA-Z]{2,}").exactMatch(this->nationality))
    {
    throw NATIONALITY;
    }
    else if(!QRegExp("^[0-9]{1,4}-[0-9]{1,2}-[0-9]{1,2}$").exactMatch(this->dateOfIssue))
    {
    throw DATEOFISSUE;
    }
    else if(!QRegExp("^[0-9]{1,4}-[0-9]{1,2}-[0-9]{1,2}$").exactMatch(this->dateOfExpire))
    {
    throw DATEOFEXPIRE;
    }
    else if(!QRegExp("^[0-9]{1,4}-[0-9]{1,2}-[0-9]{1,2}$").exactMatch(this->dateOfBirth))
    {
    throw DATEOFBIRTH;
    }
    else if(!QRegExp("[a-zA-Z]{2,}").exactMatch(this->placeOfIssue))
    {
    throw PLACEOFISSUE;
    }
    else if(!QRegExp("[a-zA-Z\s]{2,}").exactMatch(this->fatherName))
    {
    throw FATHERNAME;
    }
    else if(!QRegExp("[a-zA-Z\s]{2,}").exactMatch(this->motherName))
    {
    throw MOTHERNAME;
    }

    }
    catch(QString ex)
    {
        throw ex;
    }
    

    }@

    this Validate method is called from the event handler.


  • Lifetime Qt Champion

    Hi,

    Have a look at "Exception Safety":http://qt-project.org/doc/qt-4.8/exceptionsafety.html


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.