Xmipp  v3.23.11-Nereus
Classes | Macros | Enumerations | Functions
Error handling
Collaboration diagram for Error handling:

Classes

class  XmippError
 

Macros

#define REPORT_ERROR(nerr, ErrormMsg)   throw XmippError(nerr, ErrormMsg, __FILE__, __LINE__)
 

Enumerations

enum  ErrorType {
  ERR_FIRST_LABEL, ERR_ARG_BADCMDLINE, ERR_ARG_INCORRECT, ERR_ARG_MISSING,
  ERR_ARG_DEPENDENCE, ERR_PROG_NOTDEF, ERR_DEBUG_TEST, ERR_DEBUG_IMPOSIBLE,
  ERR_DOCFILE, ERR_GPU_MEMORY, ERR_GRID, ERR_GRID_SIZE,
  ERR_IMG_NOREAD, ERR_IMG_NOWRITE, ERR_IMG_UNKNOWN, ERR_INDEX_OUTOFBOUNDS,
  ERR_IO, ERR_IO_NOCLOSED, ERR_IO_NOTEXIST, ERR_IO_NOTOPEN,
  ERR_IO_NOPERM, ERR_IO_NOREAD, ERR_IO_NOWRITE, ERR_IO_NOTFILE,
  ERR_IO_NOTDIR, ERR_IO_NOPATH, ERR_IO_LOCKED, ERR_IO_SIZE,
  ERR_LOGIC_ERROR, ERR_MATRIX, ERR_MATRIX_DIM, ERR_MATRIX_EMPTY,
  ERR_MATRIX_SIZE, ERR_MD, ERR_MD_NOACTIVE, ERR_MD_NOOBJ,
  ERR_MD_BADLABEL, ERR_MD_MISSINGLABEL, ERR_MD_SQL, ERR_MD_OBJECTNUMBER,
  ERR_MD_BADTYPE, ERR_MD_UNDEFINED, ERR_MD_BADBLOCK, ERR_MEM_BADREQUEST,
  ERR_MEM_NOTENOUGH, ERR_MEM_NOTDEALLOC, ERR_MEM_NULLPOINTER, ERR_MMAP,
  ERR_MMAP_NOTADDR, ERR_MULTIDIM_DIM, ERR_MULTIDIM_SIZE, ERR_MULTIDIM_EMPTY,
  ERR_NOT_IMPLEMENTED, ERR_NUMERICAL, ERR_PARAM_INCORRECT, ERR_PARAM_MISSING,
  ERR_PLANS_NOCREATE, ERR_SELFILE, ERR_THREADS_NOTINIT, ERR_TYPE_INCORRECT,
  ERR_UNCLASSIFIED, ERR_VALUE_EMPTY, ERR_VALUE_INCORRECT, ERR_VALUE_NOTSET,
  ERR_LAST_LABEL
}
 

Functions

void reportWarning (const String &what)
 

Detailed Description

The error handling is performed in two different ways depending on the configuration selected for Xmipp in the file xmippConfiguration: a simple error management and a second method based on C++ exceptions.

The first method aborts the program with an error code (different for each error) while the second throws an exception which might be caught by an external routine or program.

The prototype definitions in both cases are the same as they are based on some macros which change with the configuration. Here goes a programming example considering both implementations.

// Class definition
class ReconstructingVolume :
{
...
void write(const FileName& fn) const;
...
};
// Class implementation
{
...
if (...)
REPORT_ERROR(ERR_MULTIDIM_SIZE, "Volume too small to be stored");
...
}
// Use of this class in an external program
using std::cout;
using std::endl;
...
#ifndef _NO_EXCEPTION
try
{
vol_blobs.write(fn_blobs);
}
catch (XmippError XE)
{
std::cout << XE;
std::cout << "The reconstructed volume is too small to be saved in blobs";
std::cout << "So, there is no blob version of it at this iteration";
std::cout << "I go on processing" << std::endl;
}
#else
vol_blobs.write(fn_blobs);
#endif
...

You see that the routine implementation is the same in both cases but the external program varies from one to the other as in the exception case we can catch the exception and go on processing, while in the exit mode, the program always is aborted. If you don't put the routine in a try-catch structure and an exception is thrown then a core is generated and the program is automatically aborted.

Macro Definition Documentation

◆ REPORT_ERROR

#define REPORT_ERROR (   nerr,
  ErrormMsg 
)    throw XmippError(nerr, ErrormMsg, __FILE__, __LINE__)

Show message and throw exception

This macro shows the given message and exits with the error code.

if (...)

Definition at line 211 of file xmipp_error.h.

Enumeration Type Documentation

◆ ErrorType

enum ErrorType
Enumerator
ERR_FIRST_LABEL 
ERR_ARG_BADCMDLINE 

Errors on command line parameters.

ERR_ARG_INCORRECT 

Incorrect argument received.

ERR_ARG_MISSING 

Argument missing.

ERR_ARG_DEPENDENCE 

Error with some arguments dependencies.

ERR_PROG_NOTDEF 

Required function not implemented.

ERR_DEBUG_TEST 

Just an error for debugging purpose.

ERR_DEBUG_IMPOSIBLE 

Just for debugging, situation that can't happens.

ERR_DOCFILE 

Error in docfile format.

ERR_GPU_MEMORY 

GPU memory related issues.

ERR_GRID 

Grid general error.

ERR_GRID_SIZE 

Incorrect number of GRID volumes or shapes.

ERR_IMG_NOREAD 

Cannot read image from file.

ERR_IMG_NOWRITE 

Cannot write image to file.

ERR_IMG_UNKNOWN 

Unknown image type.

ERR_INDEX_OUTOFBOUNDS 

Index out of bounds.

ERR_IO 

Input/Output general error.

ERR_IO_NOCLOSED 

File cannot be closed.

ERR_IO_NOTEXIST 

File or directory does not exist.

ERR_IO_NOTOPEN 

File cannot be open.

ERR_IO_NOPERM 

Insufficient permissions to perform operation.

ERR_IO_NOREAD 

Couldn't read from file.

ERR_IO_NOWRITE 

Couldn't write to file.

ERR_IO_NOTFILE 

It is not a file.

ERR_IO_NOTDIR 

It is not a directory.

ERR_IO_NOPATH 

Environment PATH cannot be read.

ERR_IO_LOCKED 

Error when locking/unloking a file.

ERR_IO_SIZE 

Incorrect file size.

ERR_LOGIC_ERROR 

Some logical error in the pipeline.

ERR_MATRIX 

Matrix error.

ERR_MATRIX_DIM 

Problem with matrix dimensions.

ERR_MATRIX_EMPTY 

The matrix is empty.

ERR_MATRIX_SIZE 

Problem with matrix size.

ERR_MD 

MetaData error.

ERR_MD_NOACTIVE 

No active object in MetaData.

ERR_MD_NOOBJ 

No exist requested object.

ERR_MD_BADLABEL 

Unexpected label.

ERR_MD_MISSINGLABEL 

Missing expected label.

ERR_MD_SQL 

Error in SQL of MetaData operations.

ERR_MD_OBJECTNUMBER 

Incorrect number of objects in Metadata.

ERR_MD_BADTYPE 

Bad label type.

ERR_MD_UNDEFINED 

Undefined label.

ERR_MD_BADBLOCK 

This block does not exist.

ERR_MEM_BADREQUEST 

Bad amount of memory requested.

ERR_MEM_NOTENOUGH 

There is not enough memory for allocation.

ERR_MEM_NOTDEALLOC 

Memory has not been deallocated.

ERR_MEM_NULLPOINTER 

Null pointer passed as parameter.

ERR_MMAP 

Global mmap error.

ERR_MMAP_NOTADDR 

Map addressing of file has failed.

ERR_MULTIDIM_DIM 

Incorrect MultidimArray dimensions.

ERR_MULTIDIM_SIZE 

Incorrect MultidimArray size.

ERR_MULTIDIM_EMPTY 

MultidimArray is empty.

ERR_NOT_IMPLEMENTED 

Case or algorithm not implemented yet.

ERR_NUMERICAL 

Error related to numerical calculation.

ERR_PARAM_INCORRECT 

Parameter incorrect.

ERR_PARAM_MISSING 

Parameter missing.

ERR_PLANS_NOCREATE 

FFT Plan cannot be created.

ERR_SELFILE 

Error in docfile format.

ERR_THREADS_NOTINIT 

Threads cannot be initiated.

ERR_TYPE_INCORRECT 

Incorrect type received.

ERR_UNCLASSIFIED 

Just to locate unclassified errors.

ERR_VALUE_EMPTY 

Empty value.

ERR_VALUE_INCORRECT 

Incorrect value received.

ERR_VALUE_NOTSET 

Value has not been set.

ERR_LAST_LABEL 

Definition at line 109 of file xmipp_error.h.

110 {
116 
118 
121 
122  ERR_DOCFILE,
123 
125  ERR_GRID,
126  ERR_GRID_SIZE,
127 
131 
133 
134  ERR_IO,
138  ERR_IO_NOPERM,
139  ERR_IO_NOREAD,
142  ERR_IO_NOTDIR,
143  ERR_IO_NOPATH,
144  ERR_IO_LOCKED,
145  ERR_IO_SIZE,
146 
148 
149  ERR_MATRIX,
153 
154  ERR_MD,
156  ERR_MD_NOOBJ,
159  ERR_MD_SQL,
163  ERR_MD_BADBLOCK ,
164 
169 
170  ERR_MMAP,
172 
176 
178 
179  ERR_NUMERICAL,
180 
183 
185 
186  ERR_SELFILE,
187 
189 
191 
193 
197 
199 };
Argument missing.
Definition: xmipp_error.h:114
Index out of bounds.
Definition: xmipp_error.h:132
Just to locate unclassified errors.
Definition: xmipp_error.h:192
Grid general error.
Definition: xmipp_error.h:125
No active object in MetaData.
Definition: xmipp_error.h:155
Errors on command line parameters.
Definition: xmipp_error.h:112
Empty value.
Definition: xmipp_error.h:194
Parameter incorrect.
Definition: xmipp_error.h:181
Case or algorithm not implemented yet.
Definition: xmipp_error.h:177
MultidimArray is empty.
Definition: xmipp_error.h:175
Just an error for debugging purpose.
Definition: xmipp_error.h:119
Error with some arguments dependencies.
Definition: xmipp_error.h:115
Problem with matrix size.
Definition: xmipp_error.h:152
Global mmap error.
Definition: xmipp_error.h:170
No exist requested object.
Definition: xmipp_error.h:156
Just for debugging, situation that can&#39;t happens.
Definition: xmipp_error.h:120
Matrix error.
Definition: xmipp_error.h:149
Couldn&#39;t write to file.
Definition: xmipp_error.h:140
It is not a directory.
Definition: xmipp_error.h:142
Null pointer passed as parameter.
Definition: xmipp_error.h:168
There is not enough memory for allocation.
Definition: xmipp_error.h:166
The matrix is empty.
Definition: xmipp_error.h:151
Unexpected label.
Definition: xmipp_error.h:157
Unknown image type.
Definition: xmipp_error.h:130
Input/Output general error.
Definition: xmipp_error.h:134
Cannot read image from file.
Definition: xmipp_error.h:128
Incorrect MultidimArray size.
Definition: xmipp_error.h:174
Memory has not been deallocated.
Definition: xmipp_error.h:167
Cannot write image to file.
Definition: xmipp_error.h:129
Bad amount of memory requested.
Definition: xmipp_error.h:165
Incorrect number of objects in Metadata.
Definition: xmipp_error.h:160
Error in docfile format.
Definition: xmipp_error.h:186
File cannot be closed.
Definition: xmipp_error.h:135
Undefined label.
Definition: xmipp_error.h:162
Error in SQL of MetaData operations.
Definition: xmipp_error.h:159
Map addressing of file has failed.
Definition: xmipp_error.h:171
It is not a file.
Definition: xmipp_error.h:141
Problem with matrix dimensions.
Definition: xmipp_error.h:150
Required function not implemented.
Definition: xmipp_error.h:117
GPU memory related issues.
Definition: xmipp_error.h:124
Incorrect argument received.
Definition: xmipp_error.h:113
Error related to numerical calculation.
Definition: xmipp_error.h:179
MetaData error.
Definition: xmipp_error.h:154
Missing expected label.
Definition: xmipp_error.h:158
File or directory does not exist.
Definition: xmipp_error.h:136
Couldn&#39;t read from file.
Definition: xmipp_error.h:139
This block does not exist.
Definition: xmipp_error.h:163
Threads cannot be initiated.
Definition: xmipp_error.h:188
FFT Plan cannot be created.
Definition: xmipp_error.h:184
File cannot be open.
Definition: xmipp_error.h:137
Bad label type.
Definition: xmipp_error.h:161
Value has not been set.
Definition: xmipp_error.h:196
Incorrect number of GRID volumes or shapes.
Definition: xmipp_error.h:126
Error in docfile format.
Definition: xmipp_error.h:122
Error when locking/unloking a file.
Definition: xmipp_error.h:144
Environment PATH cannot be read.
Definition: xmipp_error.h:143
Incorrect MultidimArray dimensions.
Definition: xmipp_error.h:173
Incorrect file size.
Definition: xmipp_error.h:145
Incorrect type received.
Definition: xmipp_error.h:190
Insufficient permissions to perform operation.
Definition: xmipp_error.h:138
Incorrect value received.
Definition: xmipp_error.h:195
Parameter missing.
Definition: xmipp_error.h:182
Some logical error in the pipeline.
Definition: xmipp_error.h:147

Function Documentation

◆ reportWarning()

void reportWarning ( const String what)

Print a report warning and continue the execution.

Definition at line 195 of file xmipp_error.cpp.

196 {
197  String error = formatString("=== XMIPP_WARNING ===\n%s", what.c_str());
198  std::cerr << colorString(error.c_str(), MAGENTA) << std::endl;
199 }
String colorString(const char *msg, int color, int attribute, int bgcolor)
Definition: xmipp_color.cpp:28
std::string String
Definition: xmipp_strings.h:34
String formatString(const char *format,...)