Can I use exception functionally? Should I avoid it?

Asked 2 years ago, Updated 2 years ago, 120 views

The class itself that you want to use has already thrown an exception to an invalid input value.

While trying to create a method and conditional statement that checks with isblabla~() in advance,

I thought we could just wrap it up with a try.

You don't have to write dozens of lines of code.

However, this is not just an exception to the developer's mistakes

Sometimes the exception is to use it instead of a kind of conditional statement that works like part of logic.

I've seen some examples of this functional use, but I'm asking if it's the right thing to do.

Will there be no problem if I overuse it or should I avoid it?

exception

2022-09-22 21:18

1 Answers

Exceptions should be used in exceptional situations and should not be used to control program flow. A well-designed API does not force clients to write exceptions when controlling program flows. There is a high possibility that JVM will not benefit from optimization. (Effective Java 2nd Item 57.)


2022-09-22 21:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.