+ 1

What other purpose exception has

Hi I am aware that exception is to avoid crash and control some random issues into code.. Does it has other purpose as well ? What is best suited and why for exception from below option : 1. To come out of function 2. To return value from function 3. To come out of constructor 4. To come out of destructor

30th May 2022, 5:24 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 Réponses
+ 1
That's the main purpose of exceptions, to avoid code crashes. It is best suited for 1 and 2. This is because functions must accomplish a task whether or not exceptions occur. Exception handlers will be of great use here because they can help the function return a default value if an exception occurs For 3 & 4 it should be just performing another operation (like assigning a default value) should an exception occur rather than breaking out of the class' constructor/destructor
31st May 2022, 8:45 AM
Emeh Matthew
Emeh Matthew - avatar
0
Okay...sounds good.... thanks Emeh Matthew
31st May 2022, 12:02 PM
Ketan Lalcheta
Ketan Lalcheta - avatar