source: pcp/src/errors.c@ 88e890

Last change on this file since 88e890 was e6a122, checked in by Frederik Heber <heber@…>, 17 years ago

Error(): Idea and code taken from TREMOLO, now prints line number and sourc file name

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/** \file errors.c
2 * Error reporting.
3 * Contains just one function Error() which prints out a certain error message
4 * class and starts the debugger.
5 *
6 * Project: ParallelCarParrinello
7 * \author Jan Hamaekers
8 * \date 2000
9 *
10 * File: errors.c
11 * $Id: errors.c,v 1.11 2006/03/31 10:38:04 foo Exp $
12 *
13*/
14
15#include<stdlib.h>
16#include<stdio.h>
17#include"data.h"
18#include"opt.h"
19#include"errors.h"
20
21
22/** Deals with occuring errors.
23 * Prints process id followed by error according to \ref Errors.
24 * In the case of MallocError \a *SpecialData contains additional text.
25 * Launches debugger, does afterwards MPI_abort and exit
26 *
27 * \note One could add another pointer to a function
28 *
29 * \sa StartDebugger()
30 * \param error is the type of error(enum Errors) on error_msg array
31 * \param *SpecialData is a typeless pointer on special data for error treatment, here detailed error message.
32*/
33void Error_in(enum Errors error, const void *SpecialData,
34 const char *file, const int line)
35{
36 const char *const error_msg[] = {
37 "SomeError",
38 "FileOpenParams\nUnable to open parameter file\n",
39 "InitReading\n",
40 "MallocError\nUnable to allocate memory!\n",
41 };
42 int mytid;
43 MPI_Comm_rank(MPI_COMM_WORLD, &mytid);
44 fprintf(stderr, "\nProcess %i: ", mytid);
45 fprintf(stderr, "Error in file %s, line %d (%i): %s - ",
46 file, line, (int)error, error_msg[error]);
47 switch (error) {
48 case InitReading:
49 case SomeError:
50 case MallocError:
51 if (SpecialData) fprintf(stderr, "%s\n", (const char*)SpecialData);
52 break;
53 default:
54 break;
55 }
56
57 StartDebugger();
58 MPI_Abort(MPI_COMM_WORLD, (int)error);
59 exit(EXIT_FAILURE); /* exit schreibt sowieso alle Dateipuffer aus */
60}
Note: See TracBrowser for help on using the repository browser.