You need to throw an exception from your datalayer for example :
public void ConnectDatabase()
{
try
{
SqlConnection myConnection = new SqlConnection("connectionstring");
myConnection.Open();
}
catch (SqlException sqlEx)
{
throw new MyCustomException("Failed to open new SQL Connection", sqlEx);
}
}
In your Gui layer, you'll connect to the database somewhere, at that point, you need to catch your custom made exception :
try
{
DataLayerObject myObject = new DataLayerObject();
myObject.ConnectDatabase();
}
catch (MyCustomException customEx)
{
MessageBox.Show(customEx.Message);
}
Have fun!
Eduard