debugcsharpMinor
Open database and hande errors
Viewed 0 times
opendatabasehandeanderrors
Problem
How to make this code better?
if (Program.Data.DataBase.TryOpenDataBase())
{
bool result;
DataBase= new Program.Data.DataBase(out result);
if (!result)
{
if (Program.DataBase!= null)
Program.DataBase.Dispose();
Program.DataBase= null;
Log.WriteERROR("Can not open database");
Application.Exit();
return;
}
else
{
Log.WriteERROR("Can not open database");
Application.Exit();
return;
}Solution
I would remove the out parameter from the constructor. It is really confusing to read. Maybe create a function that throws an exception instead. If the database implements IDisposable you can use a using block instead.
Edit - You have some duplicate code as well:
Edit - You have some duplicate code as well:
Log.WriteERROR("Can not open database");
Application.Exit();
return;Code Snippets
Log.WriteERROR("Can not open database");
Application.Exit();
return;Context
StackExchange Code Review Q#2257, answer score: 4
Revisions (0)
No revisions yet.