0

I am a new ASP.net developer and I am trying to do add proper exception handling in my simple 3-tier web-based application. By following this post, I have done, for example, the following in the Data Access Layer (DAL) and the User Interface (UI):

DAL:

public IEnumerable<Survey> getData()
{
    List<Survey> surveysList = new List<Survey>();
    try
    {
        using (ItemsDBEntities context = new ItemsDBEntities())
        {
            surveysList = (from survey in context.Surveys
                         select new Survey()
                         {
                             ID = survey.ID,
                             startDate = survey.StartDate,
                             EndDate = survey.EndDate,
                             Description = survey.Description
                         }).ToList();
        }
    }
    catch (EntityException ex)
    {
        //something wrong about entity
        throw new ConnectionFailedException(ex);
    }
    catch (Exception ex)
    {
        //Don't know what happend... 
    }
    return surveysList;
}

Code-Behind of UI:

private void bindGrid()
{
    Survey survey = new Survey();
    try
    {
        GridView1.DataSource = survey.getData();
        GridView1.DataBind();
        GridView1.Visible = true;
    }
    catch (ConnectionFailedException)
    {
        Label1.Text = "There was a problem accessing the database, please try again.";
    }
}

However, I am still getting a red line under

ConnectionFailedException

in each tier and I don't know why, and it gave me the following error:

The type or namespace name 'ConnectionFailedException' could not be found (are you missing a using directive or an assembly reference?)TestWebsite\App_Code\DAL\Survey.cs

How can I fix this thing? I don't want to create a class for each exception type that I am going to throw it like what I have done so far. Could you please provide me with a help and example if possible?

Community
  • 1
  • 1
user3107976
  • 185
  • 1
  • 2
  • 13
  • 1
    Is the assembly that contains `ConnectionFailedException` referenced in your project? If so, do you have the appropriate `using` directives? Also, a note on exceptions: Don't catch an exception and do nothing (e.g. an empty catch block). If you can't handle the exception, let it bubble up until something that *can* handle it catches it. – Daniel Mann Feb 02 '14 at 18:35

1 Answers1

0

You haven't added Microsoft.Rfid.SpiSdk assembly reference OR Dll might be missed in the build

Namespace: Microsoft.SensorServices.Rfid.Dspi
Assembly: Microsoft.Rfid.SpiSdk (in microsoft.rfid.spisdk.dll)
Siva Charan
  • 17,940
  • 9
  • 60
  • 95
  • I don't think I am throwing the right exception. What do you think? – user3107976 Feb 02 '14 at 18:52
  • @user3107976: Error is clearing saying that "....'ConnectionFailedException' could not be found (are you missing a using directive or an assembly reference..." – Siva Charan Feb 02 '14 at 18:56