Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Try catch statement inside the try block

Tags:

java

Would there be any value using a try catch statement inside another try block?

    try{
        // some code...
        try{
            // some code...
        }catch(Exception ex){
            ex.printStackTrace();
        }
        // some code...
    }catch(Exception ex){
        ex.printStackTrace();
    }
like image 206
DRTauli Avatar asked Jan 29 '26 02:01

DRTauli


1 Answers

Yes. You might want to catch a very specific exception in the inner block, which you could handle and return to the remainder of the block...

You would normally only do this with more specific Exceptions in the inner block though, rather than the catchall.

like image 65
KingCronus Avatar answered Jan 30 '26 14:01

KingCronus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!