Answer the question
In order to leave comments, you need to log in
Is it good or bad to write your own actions?
Hello. I got into an argument with a senior software engineer about creating my own experiences. He believes that it is not worth writing them if you do not add any new functionality there (in fact, you only change the name), they say, there is no need to produce unnecessary entities. I saw / heard in some sources on the network that you need to write your own exceptions, and not throw out the Exception class or throw out a specific exception in some other, left layer (for example, a higher one; as an example, throw SQLException in the view). And this was said / written by experienced programmers. I also agree with them myself. For now, I'm trying to do just that.
So what's the best way to do it? (in terms of style, as well as maintainability and reliability of the program)
Answer the question
In order to leave comments, you need to log in
Exceptions of the Exception class really shouldn't be thrown. The exception must be specific. The standard library has exceptions for almost all occasions. This is where they should be thrown away. And if there is no suitable one, then inherit your own version.
Academically - you are right, practically - your colleague is right.
If there is no complex logic for managing exceptions, then it makes no sense to produce them.
For example, in my long practice, I have never had to do anything depending on the type of exception .
The question is posed incorrectly.
Its exception is neither good nor bad.
The question is different - "Why?"
What is the meaning of their exceptions.
Once you answer this question, you will understand "good or bad"
Here you need to look at your project.
Most often, standard Exceptions are enough, but when using your own libraries with very narrow specifics, you should get your own exceptions.
How to do it?
Exceptions should always be caught and never thrown just like that. The program in the exception should handle the exception and inform the user that an error has occurred, abort the execution of the code with the error, and take the user to the previous screen or to an area where stable operation is guaranteed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question