4

I have to add a control inside a changeCompany() in an existing class.

I suppose the code below is OK, but I have a doubt : Does the "return" order imply that a return to the original company is done ? Or is there to add a statement, unknown by me, something like revertToPreviousCompany()?

try
{
    changeCompany(companyId)
    {
        // the method will produce a message and return false if an error
        if (!this.doSomeChecks()) {               
           return;
        }          
        // much more code below 
DAXaholic
  • 33,312
  • 6
  • 76
  • 74
b2vincent
  • 610
  • 7
  • 14

1 Answers1

6

Yes that is OK as in some situations you wouldn't even be able to revert it if not done by the runtime itself.
Imagine a callstack in which you have try - catch around some code your are calling and you expect there may be thrown an error but if the code which calls your code already established a transaction your handler is not called and therefore you wouldn't have a chance to undo the changeCompany

DAXaholic
  • 33,312
  • 6
  • 76
  • 74
  • You could add that the curly braces of the `changeCompany()` statement define the scope in which the other company is used. If that scope is left (as it is done in the question with the `return` statement), the original company is used again. – FH-Inway Sep 02 '16 at 14:49