I have the following code:
static int GetLastAddedIDHelper(OleDbConnection connection)
{
try
{
// Init variables.
OleDbCommand command = null;
string cmdText = "SELECT @@IDENTITY";
if (connection != null)
command = new OleDbCommand(cmdText, connection);
else
throw new ArgumentNullException("connection", "The connection was passed as null. Therefore the globally used connection is used but was never set.");
return (int)command.ExecuteScalar();
}
catch (Exception ex) { throw ex; }
}
public static int GetLastAddedID()
{
try
{
return GetLastAddedIDHelper(_Connection);
}
catch (Exception ex) { throw ex; }
}
private void Button_Click_Action()
{
try
{
int i = AccessDbServiceBase.GetLastAddedID();
}
catch (Exception ex)
{
MessageBox.Show(ExceptionHandler.GetExceptionMessage(ex));
}
}
The above code will get the last inserted ID from an Access database for me. Now, to do this, Button_Click_Action will call GetLastAddedID and that will call GetLastAddedIDHelper. When a exception occurs in GetLastAddedIDHelper, I throw the exception up to the main method Button_Click_Action.
I'm wondering if I'm doing this the correct way like, is the throw in GetLastAddedID necessary, should I use throw instead of throw ex, ...?