G
Guest
Hi,
I have a function that adds data to a database and I want to return true if
the database was updated and false if there was a problem, so I am using a
try... catch block...
My problem is that I can return true ok is the routine succeeds but where do
I put the return false; statement id the process fails - I get a compile
error say unreachable code with whatever i try...
Code snippet:
public bool Add()
{
try
{
// Do stuff
return true;
}
catch (Exception ex)
{
throw new Exception ("Unable to update database " + ex.Message)
}
}
If i put return false before the throw then the throw is unreachable, if I
put it after then the return is unreachable.... what is the proper way to do
this??
Thanks in advance
I have a function that adds data to a database and I want to return true if
the database was updated and false if there was a problem, so I am using a
try... catch block...
My problem is that I can return true ok is the routine succeeds but where do
I put the return false; statement id the process fails - I get a compile
error say unreachable code with whatever i try...
Code snippet:
public bool Add()
{
try
{
// Do stuff
return true;
}
catch (Exception ex)
{
throw new Exception ("Unable to update database " + ex.Message)
}
}
If i put return false before the throw then the throw is unreachable, if I
put it after then the return is unreachable.... what is the proper way to do
this??
Thanks in advance