# How to catch errors in VTK

**URL:** https://discourse.vtk.org/t/how-to-catch-errors-in-vtk/1100
**Category:** Support
**Created:** [June 7, 2019, 7:44pm UTC](https://discourse.vtk.org/t/how-to-catch-errors-in-vtk/1100 "2019-06-07T19:44:01Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [June 7, 2019, 8:02pm UTC](https://discourse.vtk.org/t/how-to-catch-errors-in-vtk/1100/3 "2019-06-07T20:02:29Z")

</div>

I usually report errors using vtkErrorMacro and capture them in tests using a custom [vtkTestingOutputWindow](https://github.com/Slicer/Slicer/blob/master/Libs/vtkAddon/vtkTestingOutputWindow.h).

The main difference compared to using an explicit error observer (as shown in @lorensen’s example above) is that using a custom output window you capture all errors from all filters and you do not need to add any extra code to your tests (unless you want to check for expected errors) - you just need to [add a few extra lines into your CMakeLists.txt](https://github.com/Slicer/Slicer/blob/85f292af53eec404d659239926ed1acbd31236dc/Libs/MRML/Core/Testing/CMakeLists.txt#L3-L5).

We have hundreds of tests using this method, see for example [how expected errors are defined here](https://github.com/Slicer/Slicer/blob/85f292af53eec404d659239926ed1acbd31236dc/Libs/MRML/Core/Testing/vtkMRMLDisplayableHierarchyNodeTest3.cxx#L262-L268).

---

_[View the full topic](https://discourse.vtk.org/t/how-to-catch-errors-in-vtk/1100)._
