+ 8
I dont understand why we need exceptions!?
11 ответов
+ 8
thanks)) now it seems clearer. I guess I need practise with them & everything will be fine.
+ 7
well, a code needs to be flawless, a perfect system. but there is times where you can't prevent neither know what the input will be, and in that case, if something is wrong, or maybe the code doesn't know how to work with it, you need to handle this situation and exceptions are these handlers! usually for outputting the error message but also to know how to proceed, log and etc
+ 6
look at things like microsoft word, sometimes it crashes because an error happened. If it didn't handle any errors, you would loose all your data once it crashes. But, since some of those errors are handled, the program has the chance to save your progress before failing. This is what you can do with exceptions, if you know there's a section with the potential of failing because of external reasons, then handling thoae possible errors makes the app better.
+ 3
u dont need'em they just happend and with this thing u can know what is the cause of it
+ 2
because in the real word nothing is perfect, i mean, you can made your program, if you are a good programmer maybe not gona made mistakes in your code, however, one user proabably gonna find quikly one error in your code, actually exist test tool of stress, performance, complexity to help you made your code better, moreover exceptions can be twrows in runtime to stop de execution of a code responding to logicals or business rules that prevent that user continues only if the user do the necessary corrections.
+ 1
So your program won't crache and display a message telling you the nature of the error also for debugging purposes.
0
We need them for effective error handling. If an error occurs in our program, we want to avoid system crash at all costs. This can be done with exceptions. In the try block we check for specific types of exceptions and based on the exception's type the appropriate catch block is executed. Thus, we can define clearly what the program should do when specific types of errors occur. For instance, we may want just to log the error message, to rollback the program to a previous state etc.
0
I can check for the input and if it`s an invalid input from the user, I can use a simple "if condition" which prints "input invalid, please re-enter..." (in case there is an invalid input).
This approach of "if there is a potential for a failure, verify it using an if condition and then specify the right behavior when failure is encountered..." seems enough for me.
If I can basically cover any kind of failure (i.e divide by zero etc...)
0
Ok thanks
0
It was driving me crazy!!!
0
Simple example - in math you cannot divide a number by 0 , so if a user tries to divide a number by zero , the program should not fail rather it should throw an exception stating , Number should not be divided by 0.