:orphan:
# KSPSetErrorIfNotConverged
Causes `KSPSolve()` to generate an error if the solver has not converged as soon as the error is detected. 
## Synopsis
```
#include "petscksp.h" 
#include "petscmat.h" 
PetscErrorCode KSPSetErrorIfNotConverged(KSP ksp, PetscBool flg)
```
Logically Collective


## Input Parameters

- ***ksp -*** iterative context obtained from `KSPCreate()`
- ***flg -*** `PETSC_TRUE` indicates you want the error generated



## Options Database Key

- ***-ksp_error_if_not_converged <true,false> -*** generate an error and stop the program





## Notes
Normally PETSc continues if a linear solver fails to converge, you can call `KSPGetConvergedReason()` after a `KSPSolve()`
to determine if it has converged.

A `KSP_DIVERGED_ITS` will not generate an error in a `KSPSolve()` inside a nested linear solver


## See Also
 [](ch_ksp), `KSPGetErrorIfNotConverged()`, `KSP`

## Level
intermediate

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/interface/itfunc.c.html#KSPSetErrorIfNotConverged">src/ksp/ksp/interface/itfunc.c</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex83f.F90.html">src/ksp/ksp/tutorials/ex83f.F90</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/ksp/ksp/interface/itfunc.c)


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