xref: /petsc/include/petscerror.h (revision d736bfeb4d37a01fcbdf00fe73fb60d6f0ba2142)
1 /*
2     Contains all error handling interfaces for PETSc.
3 */
4 #if !defined(__PETSCERROR_H)
5 #define __PETSCERROR_H
6 
7 PETSC_EXTERN_CXX_BEGIN
8 
9 /*
10    Defines the directory where the compiled source is located; used
11    in printing error messages. Each makefile has an entry
12    LOCDIR	  =  thedirectory
13    and bmake/common_variables includes in CCPPFLAGS -D__SDIR__=${LOCDIR}
14    which is a flag passed to the C/C++ compilers. This declaration below
15    is only needed if some code is compiled without the -D__SDIR__
16 */
17 #if !defined(__INSDIR__)
18 #define __INSDIR__ "unknowndirectory/"
19 #endif
20 
21 /*
22    Defines the function where the compiled source is located; used
23    in printing error messages. This is defined here in case the user
24    does not declare it.
25 */
26 #if !defined(__FUNCT__)
27 #define __FUNCT__ "User provided function"
28 #endif
29 
30 /*
31      These are the generic error codes. These error codes are used
32      many different places in the PETSc source code. The string versions are
33      at src/sys/error/err.c any changes here must also be made there
34      These are also define in include/finclude/petscerror.h any CHANGES here
35      must be also made there.
36 
37 */
38 #define PETSC_ERR_MIN_VALUE        54   /* should always be one less then the smallest value */
39 
40 #define PETSC_ERR_MEM              55   /* unable to allocate requested memory */
41 #define PETSC_ERR_SUP              56   /* no support for requested operation */
42 #define PETSC_ERR_SUP_SYS          57   /* no support for requested operation on this computer system */
43 #define PETSC_ERR_ORDER            58   /* operation done in wrong order */
44 #define PETSC_ERR_SIG              59   /* signal received */
45 #define PETSC_ERR_FP               72   /* floating point exception */
46 #define PETSC_ERR_COR              74   /* corrupted PETSc object */
47 #define PETSC_ERR_LIB              76   /* error in library called by PETSc */
48 #define PETSC_ERR_PLIB             77   /* PETSc library generated inconsistent data */
49 #define PETSC_ERR_MEMC             78   /* memory corruption */
50 #define PETSC_ERR_CONV_FAILED      82   /* iterative method (KSP or SNES) failed */
51 #define PETSC_ERR_USER             83   /* user has not provided needed function */
52 #define PETSC_ERR_SYS              88   /* error in system call */
53 
54 #define PETSC_ERR_ARG_SIZ          60   /* nonconforming object sizes used in operation */
55 #define PETSC_ERR_ARG_IDN          61   /* two arguments not allowed to be the same */
56 #define PETSC_ERR_ARG_WRONG        62   /* wrong argument (but object probably ok) */
57 #define PETSC_ERR_ARG_CORRUPT      64   /* null or corrupted PETSc object as argument */
58 #define PETSC_ERR_ARG_OUTOFRANGE   63   /* input argument, out of range */
59 #define PETSC_ERR_ARG_BADPTR       68   /* invalid pointer argument */
60 #define PETSC_ERR_ARG_NOTSAMETYPE  69   /* two args must be same object type */
61 #define PETSC_ERR_ARG_NOTSAMECOMM  80   /* two args must be same communicators */
62 #define PETSC_ERR_ARG_WRONGSTATE   73   /* object in argument is in wrong state, e.g. unassembled mat */
63 #define PETSC_ERR_ARG_TYPENOTSET   89   /* the type of the object has not yet been set */
64 #define PETSC_ERR_ARG_INCOMP       75   /* two arguments are incompatible */
65 #define PETSC_ERR_ARG_NULL         85   /* argument is null that should not be */
66 #define PETSC_ERR_ARG_UNKNOWN_TYPE 86   /* type name doesn't match any registered type */
67 
68 #define PETSC_ERR_FILE_OPEN        65   /* unable to open file */
69 #define PETSC_ERR_FILE_READ        66   /* unable to read from file */
70 #define PETSC_ERR_FILE_WRITE       67   /* unable to write to file */
71 #define PETSC_ERR_FILE_UNEXPECTED  79   /* unexpected data in file */
72 
73 #define PETSC_ERR_MAT_LU_ZRPVT     71   /* detected a zero pivot during LU factorization */
74 #define PETSC_ERR_MAT_CH_ZRPVT     81   /* detected a zero pivot during Cholesky factorization */
75 
76 #define PETSC_ERR_FLOP_COUNT       90
77 #define PETSC_ERR_MAX_VALUE        91  /* this is always the one more than the largest error code */
78 
79 #define PetscStringizeArg(a) #a
80 #define PetscStringize(a) PetscStringizeArg(a)
81 #define __SDIR__ PetscStringize(__INSDIR__)
82 
83 #if defined(PETSC_USE_ERRORCHECKING)
84 
85 /*MC
86    SETERRQ - Macro that is called when an error has been detected,
87 
88    Synopsis:
89    PetscErrorCode SETERRQ(MPI_Comm comm,PetscErrorCode errorcode,char *message)
90 
91    Not Collective
92 
93    Input Parameters:
94 +  errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
95 -  message - error message
96 
97   Level: beginner
98 
99    Notes:
100     Once the error handler is called the calling function is then returned from with the given error code.
101 
102     See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments
103 
104     In Fortran MPI_Abort() is always called
105 
106     Experienced users can set the error handler with PetscPushErrorHandler().
107 
108    Concepts: error^setting condition
109 
110 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
111 M*/
112 #define SETERRQ(comm,n,s)              return PetscError(comm,__LINE__,__FUNCT__,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s)
113 
114 /*MC
115    SETERRQ1 - Macro that is called when an error has been detected,
116 
117    Synopsis:
118    PetscErrorCode SETERRQ1(MPI_Comm comm,PetscErrorCode errorcode,char *formatmessage,arg)
119 
120    Not Collective
121 
122    Input Parameters:
123 +  errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
124 .  message - error message in the printf format
125 -  arg - argument (for example an integer, string or double)
126 
127   Level: beginner
128 
129    Notes:
130     Once the error handler is called the calling function is then returned from with the given error code.
131 
132    Experienced users can set the error handler with PetscPushErrorHandler().
133 
134    Concepts: error^setting condition
135 
136 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3()
137 M*/
138 #define SETERRQ1(comm,n,s,a1)          return PetscError(comm,__LINE__,__FUNCT__,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s,a1)
139 
140 /*MC
141    SETERRQ2 - Macro that is called when an error has been detected,
142 
143    Synopsis:
144    PetscErrorCode SETERRQ2(PetscErrorCode errorcode,char *formatmessage,arg1,arg2)
145 
146    Not Collective
147 
148    Input Parameters:
149 +  errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
150 .  message - error message in the printf format
151 .  arg1 - argument (for example an integer, string or double)
152 -  arg2 - argument (for example an integer, string or double)
153 
154   Level: beginner
155 
156    Notes:
157     Once the error handler is called the calling function is then returned from with the given error code.
158 
159    Experienced users can set the error handler with PetscPushErrorHandler().
160 
161    Concepts: error^setting condition
162 
163 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ3()
164 M*/
165 #define SETERRQ2(comm,n,s,a1,a2)       return PetscError(comm,__LINE__,__FUNCT__,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s,a1,a2)
166 
167 /*MC
168    SETERRQ3 - Macro that is called when an error has been detected,
169 
170    Synopsis:
171    PetscErrorCode SETERRQ3(PetscErrorCode errorcode,char *formatmessage,arg1,arg2,arg3)
172 
173    Not Collective
174 
175    Input Parameters:
176 +  errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
177 .  message - error message in the printf format
178 .  arg1 - argument (for example an integer, string or double)
179 .  arg2 - argument (for example an integer, string or double)
180 -  arg3 - argument (for example an integer, string or double)
181 
182   Level: beginner
183 
184    Notes:
185     Once the error handler is called the calling function is then returned from with the given error code.
186 
187     There are also versions for 4, 5, 6 and 7 arguments.
188 
189    Experienced users can set the error handler with PetscPushErrorHandler().
190 
191    Concepts: error^setting condition
192 
193 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
194 M*/
195 #define SETERRQ3(comm,n,s,a1,a2,a3)    return PetscError(comm,__LINE__,__FUNCT__,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3)
196 
197 #define SETERRQ4(comm,n,s,a1,a2,a3,a4) return PetscError(comm,__LINE__,__FUNCT__,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4)
198 #define SETERRQ5(comm,n,s,a1,a2,a3,a4,a5)       return PetscError(comm,__LINE__,__FUNCT__,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5)
199 #define SETERRQ6(comm,n,s,a1,a2,a3,a4,a5,a6)    return PetscError(comm,__LINE__,__FUNCT__,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6)
200 #define SETERRQ7(comm,n,s,a1,a2,a3,a4,a5,a6,a7) return PetscError(comm,__LINE__,__FUNCT__,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6,a7)
201 #define SETERRABORT(comm,n,s)     PetscError(comm,__LINE__,__FUNCT__,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s);MPI_Abort(comm,n)
202 
203 /*MC
204    CHKERRQ - Checks error code, if non-zero it calls the error handler and then returns
205 
206    Synopsis:
207    PetscErrorCode CHKERRQ(PetscErrorCode errorcode)
208 
209    Not Collective
210 
211    Input Parameters:
212 .  errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
213 
214   Level: beginner
215 
216    Notes:
217     Once the error handler is called the calling function is then returned from with the given error code.
218 
219     Experienced users can set the error handler with PetscPushErrorHandler().
220 
221     CHKERRQ(n) is fundamentally a macro replacement for
222          if (n) return(PetscError(...,n,...));
223 
224     Although typical usage resembles "void CHKERRQ(PetscErrorCode)" as described above, for certain uses it is
225     highly inappropriate to use it in this manner as it invokes return(PetscErrorCode). In particular,
226     it cannot be used in functions which return(void) or any other datatype.  In these types of functions,
227     you can use CHKERRV() which returns without an error code (bad idea since the error is ignored or
228          if (n) {PetscError(....); return(YourReturnType);}
229     where you may pass back a PETSC_NULL to indicate an error. You can also call CHKERRABORT(comm,n) to have
230     MPI_Abort() returned immediately.
231 
232     In Fortran MPI_Abort() is always called
233 
234    Concepts: error^setting condition
235 
236 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
237 M*/
238 #define CHKERRQ(n)             do {if (PetscUnlikely(n)) return PetscError(PETSC_COMM_SELF,__LINE__,__FUNCT__,__FILE__,__SDIR__,n,PETSC_ERROR_REPEAT," ");} while (0)
239 
240 #define CHKERRV(n)             do {if (PetscUnlikely(n)) {n = PetscError(PETSC_COMM_SELF,__LINE__,__FUNCT__,__FILE__,__SDIR__,n,PETSC_ERROR_REPEAT," ");return;}} while(0)
241 #define CHKERRABORT(comm,n)    do {if (PetscUnlikely(n)) {PetscError(PETSC_COMM_SELF,__LINE__,__FUNCT__,__FILE__,__SDIR__,n,PETSC_ERROR_REPEAT," ");MPI_Abort(comm,n);}} while (0)
242 #define CHKERRCONTINUE(n)      do {if (PetscUnlikely(n)) {PetscError(PETSC_COMM_SELF,__LINE__,__FUNCT__,__FILE__,__SDIR__,n,PETSC_ERROR_REPEAT," ");}} while (0)
243 
244 #ifdef PETSC_CLANGUAGE_CXX
245 
246 /*MC
247    CHKERRXX - Checks error code, if non-zero it calls the C++ error handler which throws an exception
248 
249    Synopsis:
250    void CHKERRXX(PetscErrorCode errorcode)
251 
252    Not Collective
253 
254    Input Parameters:
255 .  errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
256 
257   Level: beginner
258 
259    Notes:
260     Once the error handler throws a ??? exception.
261 
262     You can use CHKERRV() which returns without an error code (bad idea since the error is ignored)
263     or CHKERRABORT(comm,n) to have MPI_Abort() returned immediately.
264 
265    Concepts: error^setting condition
266 
267 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ
268 M*/
269 #define CHKERRXX(n)            do {if (PetscUnlikely(n)) {PetscError(PETSC_COMM_SELF,__LINE__,__FUNCT__,__FILE__,__SDIR__,n,PETSC_ERROR_IN_CXX,0);}} while(0)
270 
271 #endif
272 
273 /*MC
274    CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected
275 
276    Synopsis:
277    CHKMEMQ;
278 
279    Not Collective
280 
281   Level: beginner
282 
283    Notes:
284     Must run with the option -malloc_debug to enable this option
285 
286     Once the error handler is called the calling function is then returned from with the given error code.
287 
288     By defaults prints location where memory that is corrupted was allocated.
289 
290     Use CHKMEMA for functions that return void
291 
292    Concepts: memory corruption
293 
294 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
295           PetscMallocValidate()
296 M*/
297 #define CHKMEMQ do {PetscErrorCode _7_ierr = PetscMallocValidate(__LINE__,__FUNCT__,__FILE__,__SDIR__);CHKERRQ(_7_ierr);} while(0)
298 
299 #define CHKMEMA PetscMallocValidate(__LINE__,__FUNCT__,__FILE__,__SDIR__)
300 
301 #if defined(PETSC_UNDERSCORE_CHKERR)
302 extern  PetscErrorCode __gierr;
303 #define _   __gierr =
304 #define ___  CHKERRQ(__gierr);
305 #endif
306 
307 #define               PETSC_EXCEPTIONS_MAX  256
308 extern PetscErrorCode PetscErrorUncatchable[PETSC_EXCEPTIONS_MAX];
309 extern PetscInt       PetscErrorUncatchableCount;
310 extern PetscErrorCode PetscExceptions[PETSC_EXCEPTIONS_MAX];
311 extern PetscInt       PetscExceptionsCount;
312 
313 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscExceptionPush(PetscErrorCode);
314 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscExceptionPop(PetscErrorCode);
315 
316 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscErrorSetCatchable(PetscErrorCode,PetscTruth);
317 EXTERN PetscTruth PETSC_DLLEXPORT PetscErrorIsCatchable(PetscErrorCode);
318 /*MC
319    PetscExceptionCaught - Indicates if a specific exception zierr was caught.
320 
321    Synopsis:
322      PetscTruth PetscExceptionCaught(PetscErrorCode xierr,PetscErrorCode zierr);
323 
324    Not Collective
325 
326   Input Parameters:
327   + xierr - error code returned from PetscExceptionTry1() or other PETSc routine
328   - zierr - error code you want it to be
329 
330   Level: advanced
331 
332    Notes:
333     PETSc must not be configured using the option --with-errorchecking=0 for this to work
334 
335     Use PetscExceptionValue() to see if an error code is being "tried"
336 
337   Concepts: exceptions, exception handling
338 
339 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
340           CHKERRQ(), PetscExceptionTry1(), PetscExceptionValue()
341 M*/
342 PETSC_STATIC_INLINE PetscTruth PetscExceptionCaught(PetscErrorCode xierr,PetscErrorCode zierr)
343 {
344   PetscInt i;
345   if (xierr != zierr) return PETSC_FALSE;
346   for (i=0; i<PetscErrorUncatchableCount; i++) {
347     if (PetscErrorUncatchable[i] == zierr) {
348       return PETSC_FALSE;
349     }
350   }
351   return PETSC_TRUE;
352 }
353 
354 /*MC
355    PetscExceptionValue - Indicates if the error code is one that is currently being tried
356 
357    Synopsis:
358      PetscTruth PetscExceptionValue(PetscErrorCode xierr);
359 
360    Not Collective
361 
362   Input Parameters:
363   . xierr - error code
364 
365   Level: developer
366 
367    Notes:
368     PETSc must not be configured using the option --with-errorchecking=0 for this to work
369 
370     Use PetscExceptionCaught() to see if the current error code is EXACTLY the one you want
371 
372   Concepts: exceptions, exception hanlding
373 
374 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
375           CHKERRQ(), PetscExceptionTry1(), PetscExceptionCaught()
376 M*/
377 PETSC_STATIC_INLINE PetscTruth PetscExceptionValue(PetscErrorCode zierr)
378 {
379   PetscInt i;
380   for (i=0; i<PetscExceptionsCount; i++) {
381     if (PetscExceptions[i] == zierr) {
382       return PETSC_TRUE;
383     }
384   }
385   return PETSC_FALSE;
386 }
387 
388 /*MC
389    PetscExceptionTry1 - Runs the routine, causing a particular error code to be treated as an exception,
390          rather than an error. That is if that error code is treated the program returns to this level,
391          but does not call the error handlers
392 
393    Synopsis:
394      PetscErrorCode PetscExceptionTry1(PetscErrorCode routine(....),PetscErrorCode);
395 
396    Not Collective
397 
398   Level: advanced
399 
400    No Fortran Equivalent (see PetscExceptionPush() for Fortran)
401 
402    Notes:
403     PETSc must not be configured using the option --with-errorchecking=0 for this to work
404 
405   Note: In general, the outer most try on an exception is the one that will be caught (that is trys down in
406         PETSc code will not usually handle an exception that was issued above). See SNESSolve() for an example
407         of how the local try is ignored if a higher (in the stack) one is also in effect.
408 
409   Concepts: exceptions, exception hanlding
410 
411 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
412           CHKERRQ(), PetscExceptionCaught(), PetscExceptionPush(), PetscExceptionPop()
413 M*/
414 extern PetscErrorCode PetscExceptionTmp,PetscExceptionTmp1;
415 #define PetscExceptionTry1(a,b) (PetscExceptionTmp1 = PetscExceptionPush(b)) ? PetscExceptionTmp1 : (PetscExceptionTmp1 = a, (PetscExceptionTmp = PetscExceptionPop(b)) ? PetscExceptionTmp : PetscExceptionTmp1)
416 
417 /*
418    Used by PetscExceptionTrySync(). Returns zierr on ALL processes in comm iff xierr is zierr on at least one process and zero on all others.
419 */
420 PETSC_STATIC_INLINE PetscErrorCode PetscExceptionTrySync_Private(MPI_Comm comm,PetscErrorCode xierr,PetscErrorCode zierr)
421 {
422   PetscReal      in[2],out[2];
423   PetscErrorCode ierr;
424 
425   if (xierr != zierr) return xierr;
426 
427   in[0] = xierr;
428   in[1] = 0.0;   /* dummy value */
429 
430   ierr = MPI_Allreduce(in,out,2,MPIU_REAL,0,comm); if (ierr) {;}
431   return xierr;
432 }
433 
434 /*MC
435    PetscExceptionTrySyncNorm - Runs the routine, causing a particular error code to be treated as an exception,
436          rather than an error. That is if that error code is treated the program returns to this level,
437          but does not call the error handlers
438 
439    Synopsis:
440      PetscExceptionTrySyncNorm(MPI_Comm comm,PetscErrorCode routine(....),PetscErrorCode);
441 
442      Collective on Comm
443 
444   Level: advanced
445 
446    Notes: This synchronizes the error code across all processes in the communicator IF the code matches PetscErrorCode. The next
447      call with an MPI_Reduce()/MPI_Allreduce() MUST be VecNorm() [We can added VecDot() and maybe others as needed].
448 
449     PETSc must not be configured using the option --with-errorchecking=0 for this to work
450 
451   Note: In general, the outer most try on an exception is the one that will be caught (that is trys down in
452         PETSc code will not usually handle an exception that was issued above). See SNESSolve() for an example
453         of how the local try is ignored if a higher (in the stack) one is also in effect.
454 
455   Concepts: exceptions, exception hanlding
456 
457 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
458           CHKERRQ(), PetscExceptionCaught(), PetscExceptionPush(), PetscExceptionPop(), PetscExceptionTry1()
459 M*/
460 #define PetscExceptionTrySyncNorm(comm,a,b) (PetscExceptionTmp = PetscExceptionPush(b)) ? PetscExceptionTmp : \
461                                         (PetscExceptionTmp = a , PetscExceptionPop(b),PetscExceptionTrySyncNorm_Private(comm,PetscExceptionTmp,b))
462 
463 #else
464 
465 /*
466     These are defined to be empty for when error checking is turned off, with ./configure --with-errorchecking=0
467 */
468 
469 #define SETERRQ(c,n,s)
470 #define SETERRQ1(c,n,s,a1)
471 #define SETERRQ2(c,n,s,a1,a2)
472 #define SETERRQ3(c,n,s,a1,a2,a3)
473 #define SETERRQ4(c,n,s,a1,a2,a3,a4)
474 #define SETERRQ5(c,n,s,a1,a2,a3,a4,a5)
475 #define SETERRQ6(c,n,s,a1,a2,a3,a4,a5,a6)
476 #define SETERRABORT(comm,n,s)
477 
478 #define CHKERRQ(n)     ;
479 #define CHKERRABORT(comm,n) ;
480 #define CHKERRCONTINUE(n) ;
481 #define CHKMEMQ        ;
482 
483 #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR)
484 #define _
485 #define ___
486 #endif
487 
488 #define PetscExceptionPush(a)                0
489 #define PetscExceptionPop(a)                 0
490 #define PetscErrorSetCatchable(a,b)          0
491 #define PetscErrorIsCatchable(a)             PETSC_FALSE
492 
493 #define PetscExceptionCaught(a,b)            PETSC_FALSE
494 #define PetscExceptionValue(a)               PETSC_FALSE
495 #define PetscExceptionTry1(a,b)              a
496 #define PetscExceptionTrySyncNorm(comm,a,b)  a
497 
498 #endif
499 
500 /*E
501   PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers
502 
503   Level: advanced
504 
505   PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated
506 
507   Developer Notes: This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandling()
508 
509 .seealso: PetscError(), SETERRXX()
510 E*/
511 typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType;
512 
513 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscErrorPrintfInitialize(void);
514 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscErrorMessage(int,const char*[],char **);
515 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
516 #if defined(PETSC_CLANGUAGE_CXX) && !defined(PETSC_USE_EXTERN_CXX)
517 #include <sstream>
518 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscTraceBackErrorHandlerCxx(MPI_Comm,int,const char *,const char *,const char *,PetscErrorCode,PetscErrorType,const char*,void*);
519 #endif
520 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
521 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
522 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
523 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
524 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
525 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
526 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscError(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...) PETSC_PRINTF_FORMAT_CHECK(7,8);
527 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*);
528 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPopErrorHandler(void);
529 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDefaultSignalHandler(int,void*);
530 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*);
531 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPopSignalHandler(void);
532 
533 typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
534 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscSetFPTrap(PetscFPTrap);
535 
536 /*
537       Allows the code to build a stack frame as it runs
538 */
539 #if defined(PETSC_USE_DEBUG)
540 
541 #define PETSCSTACKSIZE 64
542 
543 typedef struct  {
544   const char *function[PETSCSTACKSIZE];
545   const char *file[PETSCSTACKSIZE];
546   const char *directory[PETSCSTACKSIZE];
547         int  line[PETSCSTACKSIZE];
548         int currentsize;
549 } PetscStack;
550 
551 extern PETSC_DLLEXPORT PetscStack *petscstack;
552 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscStackCopy(PetscStack*,PetscStack*);
553 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscStackPrint(PetscStack*,FILE* fp);
554 
555 #define PetscStackActive (petscstack != 0)
556 
557 
558 /*MC
559    PetscFunctionBegin - First executable line of each PETSc function
560         used for error handling.
561 
562    Synopsis:
563    void PetscFunctionBegin;
564 
565    Not Collective
566 
567    Usage:
568 .vb
569      int something;
570 
571      PetscFunctionBegin;
572 .ve
573 
574    Notes:
575      Not available in Fortran
576 
577    Level: developer
578 
579 .seealso: PetscFunctionReturn()
580 
581 .keywords: traceback, error handling
582 M*/
583 #define PetscFunctionBegin \
584   {\
585    if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {    \
586     petscstack->function[petscstack->currentsize]  = __FUNCT__; \
587     petscstack->file[petscstack->currentsize]      = __FILE__; \
588     petscstack->directory[petscstack->currentsize] = __SDIR__; \
589     petscstack->line[petscstack->currentsize]      = __LINE__; \
590     petscstack->currentsize++; \
591   }}
592 
593 #define PetscStackPush(n) \
594   {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {    \
595     petscstack->function[petscstack->currentsize]  = n; \
596     petscstack->file[petscstack->currentsize]      = "unknown"; \
597     petscstack->directory[petscstack->currentsize] = "unknown"; \
598     petscstack->line[petscstack->currentsize]      = 0; \
599     petscstack->currentsize++; \
600   }}
601 
602 #define PetscStackPop \
603   {if (petscstack && petscstack->currentsize > 0) {     \
604     petscstack->currentsize--; \
605     petscstack->function[petscstack->currentsize]  = 0; \
606     petscstack->file[petscstack->currentsize]      = 0; \
607     petscstack->directory[petscstack->currentsize] = 0; \
608     petscstack->line[petscstack->currentsize]      = 0; \
609   }};
610 
611 /*MC
612    PetscFunctionReturn - Last executable line of each PETSc function
613         used for error handling. Replaces return()
614 
615    Synopsis:
616    void PetscFunctionReturn(0);
617 
618    Not Collective
619 
620    Usage:
621 .vb
622     ....
623      PetscFunctionReturn(0);
624    }
625 .ve
626 
627    Notes:
628      Not available in Fortran
629 
630    Level: developer
631 
632 .seealso: PetscFunctionBegin()
633 
634 .keywords: traceback, error handling
635 M*/
636 #define PetscFunctionReturn(a) \
637   {\
638   PetscStackPop; \
639   return(a);}
640 
641 #define PetscFunctionReturnVoid() \
642   {\
643   PetscStackPop; \
644   return;}
645 
646 
647 #else
648 
649 #define PetscFunctionBegin
650 #define PetscFunctionReturn(a)  return(a)
651 #define PetscFunctionReturnVoid() return
652 #define PetscStackPop
653 #define PetscStackPush(f)
654 #define PetscStackActive        0
655 
656 #endif
657 
658 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscStackCreate(void);
659 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscStackView(PetscViewer);
660 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscStackDestroy(void);
661 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscStackPublish(void);
662 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscStackDepublish(void);
663 
664 
665 PETSC_EXTERN_CXX_END
666 #endif
667