+ 3

Seriously,What's The Difference?

So Lately I've Been Heard About Exception And How To Handle It,Yet,I Feel Like Exception Is More Like An Error,Confused,I Want To Ask You Guys,What's The Difference Between These Two?(Exception And Error)

15th Dec 2021, 8:22 AM
Lidya Reine
Lidya Reine - avatar
3 Answers
+ 3
Exceptions are error handling, we use exceptions if we encounter an error, so for example; let's say we want an int as input from the user, and they provide a string.. Instead of exiting the program, we could throw a specific error message back to the user, or we could simply set a default value of the int, so that the program continues to run.
15th Dec 2021, 8:40 AM
Rosenkilde
Rosenkilde - avatar
+ 3
Exception is a way of saying when something you don't want to happen may happen. That's an exception. The error is when that thing happens. Example assuming you have an exception called DontWriteTwo to prevent a user from writing 2. When that exception is not handled and the user writes 2, you'll get an error. So you can handle the DontWriteTwo exception to prevent that error.
16th Dec 2021, 8:56 AM
ŰŹÙˆŰ±ŰŻÙ† ŰąÙ‡Ùˆ Ù…Ű§ÙˆÙ„ÛŒ
ŰŹÙˆŰ±ŰŻÙ† ŰąÙ‡Ùˆ Ù…Ű§ÙˆÙ„ÛŒ - avatar
+ 2
Basically in some languages there are two types of ‘errors’. Those that an app can recover from (Exceptions) and those that are so severe it is impossible recover from (Errors). For example in java if you try to access the second element of a zero size array an exception will occur which is trivial to recover from (try/catch block). However if you were to make a new array with a size of 2^31-1 an OutOfMemoryError will occur which will not be so easy to recover from. You can still catch the error but then what? You are out of memory so you can’t really do anything.
15th Dec 2021, 11:33 AM
Kamen Studentov
Kamen Studentov - avatar