Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
In Master page:

pirvate bool vcf()
{
    object[] parameters = new object[] { };

        CallContentFunction(StringConstants.validCompulsoryFields);//from here control goes to following, within the same Page i.e. Master Page
}


private object CallContentFunction(string methodName, params object[] parameters)
    {
        try
        {
                Type contentType = this.Page.GetType();
                System.Reflection.MethodInfo mi = contentType.GetMethod(methodName);
                if (mi == null) return null;
                mi.Invoke(this.Page, parameters);//Consider mi!=null her & then   from here control goes to content page's ValidCompulsoryFields()
                return mi;
        }
        catch (Exception exception)
        {
           throw exception;
        }
    }

In Content Page:

public bool ValidCompulsoryFields()
   {
       //Check for State
       {
           try
           {
               if (StateName1.Text == string.Empty || StateName1.Text == StringConstants.select ||
                   StateName1.SelectedValue.ToString() == StringConstants.select)   //if condition goes true,
               {

                   throw new Exception(ErrorConstants.selectTheState);
               }

               return true;
           }
           catch (Exception exception)
           {
               MessageBox.Show(exception.Message);
               StateName1.Focus();
               throw exception;
               // return false;

           }

       }
   }<-------- At this point I'm getting an error message as, "Exception was Unhandelled by User Code"".

In short,I want to bring Exception out from the content page to the Master Page which is showing the above error message.
Posted
Updated 7-Apr-11 22:52pm
v3
Comments
durgeshtupkar10 7-Apr-11 8:36am    
What?
Ashishmau 8-Apr-11 6:24am    
Be clear

1 solution

An article on how to deal with Try Catch blocks (in VB, but the rules still apply in C#). Using Try... Catch..., Finally![^]
If your Exception is unhandled that is because the Exception cannot find any Catch blocks up the stack.
Catching an Exception and rethrowing it is not best practice, Use Throw instead. Catching an Exception and ONLY rethrowing it is just plain useless... When an Exception is handled at user level (the user has been notified) it is usually not necessary to throw again...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900