# MatSetErrorIfFailure
Causes `Mat` to generate an immediate error, for example a zero pivot, is detected. 
## Synopsis
```
#include "petscmat.h"  
PetscErrorCode MatSetErrorIfFailure(Mat mat, PetscBool flg)
```
Logically Collective on mat


## Input Parameters

- ***mat -*** matrix obtained from `MatCreate()`
- ***flg -*** `PETSC_TRUE` indicates you want the error generated





## Note
If this flag is not set then the matrix operation will note the error and continue. The error may cause a later `PC` or `KSP` error
or result in a `KSPConvergedReason` indicating the method did not converge.


## See Also
 `PCSetErrorIfFailure()`, `KSPConvergedReason`, `SNESConvergedReason`

## Level
advanced

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/utils/gcreate.c.html#MatSetErrorIfFailure">src/mat/utils/gcreate.c</A>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/mat/utils/gcreate.c)


[Index of all Mat routines](index.md)  
[Table of Contents for all manual pages](/docs/manualpages/index.md)  
[Index of all manual pages](/docs/manualpages/singleindex.md)  
