Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ exceptions, can what() be NULL?

Tags:

People also ask

Can an exception be null?

A NullReferenceException exception is thrown by a method that is passed null . Some methods validate the arguments that are passed to them. If they do and one of the arguments is null , the method throws an System.

Can exception stack trace null?

Yes. If you create a new Exception() and don't throw it, every property except Data and Message will be null.

Can we catch null pointer exception C++?

There's no such thing as "null pointer exception" in C++. The only exceptions you can catch, is the exceptions explicitly thrown by throw expressions (plus, as Pavel noted, some standard C++ exceptions thrown intrinsically by standard operator new , dynamic_cast etc). There are no other exceptions in C++.

Why use exceptions?

Exceptions provide the means to separate the details of what to do when something out of the ordinary happens from the main logic of a program. In traditional programming, error detection, reporting, and handling often lead to confusing spaghetti code.


Can a caught std::exception ever have what() being NULL?

Is the checking for e.what() below overhead?

//...
}
catch (const std::exception& e)
{
  std::string error;
  if(e.what())
    error = e.what();
}