One of the main attempts to catch methods calling methods that do not implement try-catch

I have a method doSomething()that has one catch try block in which I call another method.

    public void doSomething()  
    {  
       try
        {
            doSomethingElse();
        }
        catch
        {
            // catch implementation goes here
        }

    } 

In this other method doSomethingElse(), I have no catch try block. I mean the main try-catch method for handling exceptions. If doSomethingElse()there are exceptions, they will bubble up to the doSomething try-catch block method.

Is there something wrong with this approach?

Thank you for your time.

+3
source share
4 answers

This is completely legal.

Let the exceptions bubble up to where you can / know what to do with them.

try/catch, .

catch - ( , , , , catch).

+2

.

, . ; catch (Exception) throw. , , , Exception.

+2

. , , doSomethingElse() . , , - . -, . doSomethingElse() , doSomething() , . , , .

, . . AccessViolation FatalExecutionEngineError, , CLR , . , , . , . , .

+2

ok, ; doSomethingElse()

+1

Source: https://habr.com/ru/post/1769127/


All Articles