Exception exception in try block, not catch block?

I have inherited code in our project that looks like this. This is a class method.

protected override bool Load()
{
    DataAccess.SomeEntity record;

    try
    {
        record = _repository.Get(t => t.ID.Equals(ID));

        if (record == null)
        {
            throw new InvalidOperationException("failed to initialize the object.");
        }
        else
        {
            this.ID = record.ID;
            // this.OtherProperty = record.SomeProperty;
            // etc
        } 
    }
    catch (Exception)
    {
        throw;
    }

    return true;
}

If I then call this Load method from my user interface level, I would probably want to have a catch try block to catch any exception caused by instance loading failure, for example. InvalidOperationException, but the code above seems wrong to me.

Would an InvalidOperationException be a catch expression? this catch statement will also catch potential problems with _repository.Get, as well as potential problems with setting properties if the record is valid.

, , , , catch catch Get catch, , , , catch , :

protected override bool Load()
{
    DataAccess.SomeEntity record;

    record = _repository.Get(t => t.ID.Equals(ID));

    if (record == null)
    {
        throw new InvalidOperationException("failed to initialize the object.");
    }
    else
    {
        this.ID = record.ID;
        // this.OtherProperty = record.SomeProperty;
        // etc
    } 

    return true;
}

, , , .

+5
5

:

catch (Exception)
{
    throw;
}

. , , , . throw . .

+6

(Ithink), , . Load(), .

0

! . , , . , -, .

, , ,

0

catch, throw, . , / , , .

, .

0

, , , , . catch catch, , . , , , , catch try . , - - asp.net, , - 't catch catch, , , , .

!

0

All Articles