1 /* glpenv04.c (error handling) */
3 /***********************************************************************
4 * This code is part of GLPK (GNU Linear Programming Kit).
6 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
7 * 2009, 2010 Andrew Makhorin, Department for Applied Informatics,
8 * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
9 * E-mail: <mao@gnu.org>.
11 * GLPK is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * GLPK is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
19 * License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
23 ***********************************************************************/
27 /***********************************************************************
30 * glp_error - display error message and terminate execution
34 * void glp_error(const char *fmt, ...);
38 * The routine glp_error (implemented as a macro) formats its
39 * parameters using the format control string fmt, writes the formatted
40 * message to the terminal, and abnormally terminates the program. */
42 static void error(const char *fmt, ...)
43 { ENV *env = get_env_ptr();
45 env->term_out = GLP_ON;
49 xprintf("Error detected in file %s at line %d\n", env->err_file,
51 if (env->err_hook != NULL)
52 env->err_hook(env->err_info);
58 _glp_error glp_error_(const char *file, int line)
59 { ENV *env = get_env_ptr();
65 /***********************************************************************
68 * glp_assert - check for logical condition
73 * void glp_assert(int expr);
77 * The routine glp_assert (implemented as a macro) checks for a logical
78 * condition specified by the parameter expr. If the condition is false
79 * (i.e. the value of expr is zero), the routine writes a message to
80 * the terminal and abnormally terminates the program. */
82 void glp_assert_(const char *expr, const char *file, int line)
83 { glp_error_(file, line)("Assertion failed: %s\n", expr);
87 /***********************************************************************
90 * glp_error_hook - install hook to intercept abnormal termination
94 * void glp_error_hook(void (*func)(void *info), void *info);
98 * The routine glp_error_hook installs a user-defined hook routine to
99 * intercept abnormal termination.
101 * The parameter func specifies the user-defined hook routine. It is
102 * called from the routine glp_error before the latter calls the abort
103 * function to abnormally terminate the application program because of
104 * fatal error. The parameter info is a transit pointer, specified in
105 * the corresponding call to the routine glp_error_hook; it may be used
106 * to pass some information to the hook routine.
108 * To uninstall the hook routine the parameters func and info should be
109 * specified as NULL. */
111 void glp_error_hook(void (*func)(void *info), void *info)
112 { ENV *env = get_env_ptr();
114 { env->err_hook = NULL;
115 env->err_info = NULL;
118 { env->err_hook = func;
119 env->err_info = info;