| [a0bcf1] | 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 | */ | 
|---|
| [e6a122] | 33 | void Error_in(enum Errors error, const void *SpecialData, | 
|---|
|  | 34 | const char *file, const int line) | 
|---|
| [a0bcf1] | 35 | { | 
|---|
|  | 36 | const char *const error_msg[] = { | 
|---|
|  | 37 | "SomeError", | 
|---|
| [e6a122] | 38 | "FileOpenParams\nUnable to open parameter file\n", | 
|---|
| [a0bcf1] | 39 | "InitReading\n", | 
|---|
| [e6a122] | 40 | "MallocError\nUnable to allocate memory!\n", | 
|---|
| [a0bcf1] | 41 | }; | 
|---|
|  | 42 | int mytid; | 
|---|
|  | 43 | MPI_Comm_rank(MPI_COMM_WORLD, &mytid); | 
|---|
|  | 44 | fprintf(stderr, "\nProcess %i: ", mytid); | 
|---|
| [e6a122] | 45 | fprintf(stderr, "Error in file %s, line %d (%i): %s - ", | 
|---|
|  | 46 | file, line, (int)error, error_msg[error]); | 
|---|
| [a0bcf1] | 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 | } | 
|---|