Udostępnij za pośrednictwem


Error Handling in Wizard JScript Files

When you create a wizard, your project includes the Default.js and Common.js files. Use these files to customize your project. See The JScript File for more information.

Your project should include error handling. The following code provides you with an example of such code.

To handle errors in JScript

  1. To catch errors when the user clicks Finish, enter the following code:

    function OnFinish(selProj, Class)
    {
       try
       {
          .....
       }
       catch(e)
       {
          if (e.description.length != 0)
             SetErrorInfo(e.description, e.number);
          return e.number
       }
    }
    
  2. Throw e from any helper script functions called in the script:

    function ExtenderFromType(strVariableType)
    {
       try
       {
          ....
       }
       catch(e)
       {
          throw e;
       }
    }
    
  3. If the parameter PREPROCESS_FUNCTION is in the .vsz file, the wizard calls CanAddATLClass. Use SetErrorInfo in case of failure and return false:

    function CanAddATLClass(oProj, oObject)
    {
       try
       {
          if (!IsATLProject(oProj))
          {
             if (!IsMFCProject(oProj, true))
             {   
                var L_CanAddATLClass_Text = "ATL classes can only be added
     to ATL, MFC EXE and MFC regular DLL projects.";
                wizard.ReportError(L_CanAddATLClass_Text);
                return false;
             }
             else
             {
                .....
                var bRet = AddATLSupportToProject(oProj);
                .....
                return bRet;
             }
          }
          return true;
       }
       catch(e)
       {
          throw e;
       }
    }
    
  4. If you must go back to the New Project or Add New Item dialog box, return VS_E_WIZBACKBUTTONPRESS:

       function OnFinish(selProj, Class)
       {
          ....
          if (!CheckAddtoProject(selProj))
          {
             return VS_E_WIZARDBACKBUTTONPRESS;
          }
       }
    

See Also

Concepts

Files Created for Your Wizard

Customizing Your Wizard