H
Harti Brandt
On Mon, 19 Jul 2004, H.A. Sujith wrote:
HS>If malloc fails what should I do?
HS>
HS>1. Exit imediately.
HS>2. Print an error message (or put a log entry) and exit.
HS>3. Print an error message (or put a log entry) and continue
HS>execution (after possibly recovering from the error).
That depends stronlgy on the concrete application. For one-shot programs
like 'ls' or so a malloc() failure is most probable a problem in the
environment and just printing a message (if possible) and exiting is the
best one can do. For programs that are long running or run under special
conditions (think of controlling software for a nuclear power plant) this
is not an option and they probably have to try to recover (and log, of
course).
HS>Printing an error message might be difficult in a graphical environment.
That's one of the reasons why such programs sometimes simply disappear
from the screen without any hint what happend.
harti
HS>If malloc fails what should I do?
HS>
HS>1. Exit imediately.
HS>2. Print an error message (or put a log entry) and exit.
HS>3. Print an error message (or put a log entry) and continue
HS>execution (after possibly recovering from the error).
That depends stronlgy on the concrete application. For one-shot programs
like 'ls' or so a malloc() failure is most probable a problem in the
environment and just printing a message (if possible) and exiting is the
best one can do. For programs that are long running or run under special
conditions (think of controlling software for a nuclear power plant) this
is not an option and they probably have to try to recover (and log, of
course).
HS>Printing an error message might be difficult in a graphical environment.
That's one of the reasons why such programs sometimes simply disappear
from the screen without any hint what happend.
harti