Returning latest database ID I want my method to use a finally block so I can be ure that my EF entity is disposed after usage, even if an exception is thrown, but I would also like to not handle exceptions in that method.


The current code works but is it possible to omit the catch{} block? Would an exception from the try{} block be re-thrown or would it be forgotten?
Is it necessary to set tm_entity to null in the finally block, or will Dispose take care of everything?


Any other suggestions are welcome!

/// &lt;summary&gt;
/// Returns ID of the latest result database.
/// &lt;/summary&gt;
/// &lt;param name="managementEntity"&gt;EF Test Management entity.&lt;/param&gt;
/// &lt;returns&gt;Latest result database ID.&lt;/returns&gt;
public static int GetLatestDatabaseIteration(TEST_MANAGEMENTEntities managementEntity)
    {
        if (managementEntity == null)
        {
            throw new ArgumentNullException("Passed entity can not be null!.");
        }

        TEST_MANAGEMENTEntities tm_entity = managementEntity;
        int? latestDatabaseID = null;
        try
        {
            latestDatabaseID = (from trb in tm_entity.TestRunsDatabases
                                select trb.DatabaseID).Max();

            if (latestDatabaseID == null)
            {
                throw new Exception("Cannot evaluate latest Test Result Database ID.");
            }
        }
        catch (Exception ex) //Could I just omit this block?
        {
            throw ex;
        }
        finally
        {
            tm_entity.Dispose();
            tm_entity = null; //is it necessary?
        }
        return (int)latestDatabaseID;
    }


EDIT:

After making suggested changes my method looks like this.

public static int GetLatestDatabaseIteration(TEST_MANAGEMENTEntities managementEntity)
    {
        if (managementEntity == null)
        {
            throw new ArgumentNullException("Passed entity can not be null!.");
        }

        TEST_MANAGEMENTEntities tmEntity = managementEntity;

        int? latestDatabaseID = (from trb in tmEntity.TestRunsDatabases
                                 select (int?)trb.DatabaseID).Max();

        if (latestDatabaseID == null)
        {
            throw new NoRecordsFoundException("Cannot evaluate latest Test Result Database ID.");
        }

        return (int)latestDatabaseID;
    }


Changes I made:   


I have renamed variables to match CamelCase.   
I have removed .Dispose on a passed reference as it would also Dispose object in the Caller method.
I have abandoned calling generic exception and replaced it with custom one that more accurately describes this exception.   


Calling .Max() if query return null may cause problems, but I will check it with UnitTests soon.
You really shouldn't rethrow caught exceptions like that.

catch (Exception ex) //Could I just omit this block?
    {
        throw ex;
    }


Erases the call stack of the exception, instead use

catch (Exception) //Could I just omit this block?
    {
        throw;
    }


However the point is moot, because the try-finally block is syntactically legal, but you should bear in mind a very major caveat (emphasis my own):


  Within a handled exception, the associated finally block is guaranteed to be run. However, if the exception is unhandled, execution of the finally block is dependent on how the exception unwind operation is triggered. That, in turn, is dependent on how your computer is set up.


As such, it would be a good idea to make sure you catch any exceptions you can reasonably expect, but then that's just standard good practice.

As an aside, I really don't like your use of caps. Type names should be PascalCase, and you should avoid underscores in type names or variable names.

Lastly, you really should throw a subclass of Exception, and never the parent class.