Default exception exceptions in C ++

I'm just wondering if a system exception throws, for example, divide by zero, actually “throws” something into the application. Can this be caught by default?

i means we can define a custom separator fn that checks for a zero divisor and throws an exception, but just thought it would be nice if that exception were thrown by default

//say I do this
int i;
try
{
i /= 0; // My compiler (gcc) did warn abt the divide by zero :-)
}
catch (...)
{
// Can we get here  for this case?
}
+3
source share
2 answers

It depends on the OS. You can do this in Visual C ++ code on Windows - catch (...) will also catch the so-called structured exceptions, which include divisions by zero, access violations, etc., but not in gcc-compiled code in Linux

+3

++ , - , undefined.

, :

i /= 0; // My compiler (gcc) did warn abt the divide by zero :-)

, , , .

+1

Source: https://habr.com/ru/post/1715626/


All Articles