+ 8

I dont understand why we need exceptions!?

24th Nov 2016, 9:16 PM
LyannaM
LyannaM - avatar
11 odpowiedzi
+ 8
thanks)) now it seems clearer. I guess I need practise with them & everything will be fine.
24th Nov 2016, 9:30 PM
LyannaM
LyannaM - avatar
+ 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
24th Nov 2016, 9:27 PM
Danilo Souza Magdaleno
Danilo Souza Magdaleno - avatar
+ 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.
24th Nov 2016, 9:25 PM
Alejandro Aristizabal
Alejandro Aristizabal - avatar
+ 3
u dont need'em they just happend and with this thing u can know what is the cause of it
13th Jan 2017, 6:03 AM
XOPGAMINGX _300
XOPGAMINGX _300 - avatar
+ 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.
17th Jan 2017, 4:03 AM
Jahndev
Jahndev - avatar
+ 1
So your program won't crache and display a message telling you the nature of the error also for debugging purposes.
21st Dec 2016, 5:14 AM
Adil Yousfi
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.
24th Nov 2016, 11:15 PM
Miltiadis Siavvas
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...)
14th Dec 2016, 4:06 AM
jyoti nayal
jyoti nayal - avatar
0
Ok thanks
1st Feb 2017, 11:11 PM
halobeastking
0
It was driving me crazy!!!
21st Jun 2017, 6:48 PM
David Chacon
David Chacon - avatar
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.
6th May 2019, 11:31 AM
Krishna
Krishna - avatar