
Hello Ramyasri.
An exception is not raised automatically for every error.
A catch block runs only if something is thrown.
Case 1: When you don’t need throw
Some C++ operations already know how to handle failure.
Memory allocation with new is one of them.
If new fails:
C++ automatically throws an exception
Control jumps directly to
catchYou don’t need to write
throwyourself
So it feels like “magic”, but it’s actually built-in behavior.
Case 2: When you do need throw
In normal program logic (conditions, calculations, validations) and the current task in the lesson is calculation:
C++ does not assume anything is an error
Even if something is “wrong” by your logic, C++ keeps running
No exception exists unless you explicitly create one
So unless you write throw, there is:
No exception
Nothing for
catchto catchNo error message
I hope I was able to explain it clearly. If you still have any confusion, please feel free to message me again and I’ll be happy to explain it in more detail.
Thank you for your question. keep up the great work in your learning journey! I look forward to hearing more questions from you.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer