+ 2
Can we use throw outside try or catch block ?
Usually we use throw when we want to raise our own exception in program and handle it, but what happens when we use throw wherever required without try or catch blocks just like if-else?
1 Answer
+ 1
Probably your program will just run unnecessarily slow.
Usually with if and else, switch or ternary operator, you compare conditions or even just values. Doesn't get any easier than that.
So you should use exception handling for cases where that's not good enough, where you can't predetermine conclusively what's going to happen.