With Python, I could get the name of the exception easily as follows.
- run the code, i.e. x = 3/0 to get the exception from python
- “ZeroDivisionError: integer division or modulo by zero” tells me this is ZeroDivisionError
- Modify the code i.e. try: x=3/0 except ZeroDivisionError: DO something
Is there any similar way to find the exception name with C++?
When I run the x = 3/0, the compiled binary just throws ‘Floating point exception’, which is not so useful compared to python.
While you can’t easily ask for the name of the exception, if the exception derives from
std::exceptionyou can find out the specified reason it was shown withwhat():On a side note, dividing by 0 is not guaranteed to raise a C++ exception (I think the MS platforms may do that but you won’t get that on Linux).