How Can I Force Execution to the Catch Block?

后端 未结 12 1222
野趣味
野趣味 2021-01-17 07:46

I am wondering can try..catch force execution to go into the catch and run code in there?

here example code:

try {
    if (         


        
12条回答
  •  -上瘾入骨i
    2021-01-17 08:15

    Yes, if you throw the exception that you intend to catch from within the try, it will be caught in the catch section.

    I have to ask you why you would want to do this though? Exception handling is not meant to be a substitute for control flow.

提交回复
热议问题