ITK/Examples/Developer/Exceptions: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
No edit summary
(deprecated content that is moved to sphinx)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
==Description==
{{warning|1=The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releasesIn many cases, the examples on this page no longer conform to the best practices for modern ITK versions.}}
This example demonstrates how to throw an exception.
 
==ITK Classes Demonstrated==
 
==Exceptions.cxx==
<source lang="cpp">
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
 
#include "ImageSource.h"
 
int main(int, char*[])
{
  // Setup types
  typedef itk::Image<unsigned char, 2>  ImageType;
  ImageType::Pointer image = ImageType::New();
 
  // Create and the filter
  typedef itk::ImageFilter<ImageType>  FilterType;
  FilterType::Pointer filter = FilterType::New();
  filter->SetInput(image);
  filter->Update();
 
  return EXIT_SUCCESS;
}
</source>
 
==ImageSource.h==
<source lang="cpp">
#ifndef __itkImageFilter_h
#define __itkImageFilter_h
 
#include "itkImageToImageFilter.h"
 
#include <set>
 
namespace itk
{
template< class TImage>
class ImageFilter:public ImageToImageFilter< TImage, TImage >
{
public:
 
  /** Standard class typedefs. */
  typedef ImageFilter            Self;
  typedef ImageToImageFilter< TImage, TImage > Superclass;
  typedef SmartPointer< Self >        Pointer;
 
  /** Method for creation through the object factory. */
  itkNewMacro(Self);
 
  /** Run-time type information (and related methods). */
   itkTypeMacro(ImageFilter, ImageToImageFilter);
 
protected:
  ImageFilter(){}
  ~ImageFilter(){}
 
  /** Does the real work. */
  virtual void GenerateData();
 
private:
  ImageFilter(const Self &); //purposely not implemented
  void operator=(const Self &);  //purposely not implemented
 
};
} //namespace ITK
 
 
#ifndef ITK_MANUAL_INSTANTIATION
#include "ImageFilter.txx"
#endif
 
 
#endif // __itkImageFilter_h
</source>
 
==ImageSource.txx==
<source lang="cpp">
#ifndef __itkImageFilter_txx
#define __itkImageFilter_txx
 
#include "ImageFilter.h"
#include "itkObjectFactory.h"
#include "itkImageRegionIterator.h"
#include "itkImageRegionConstIterator.h"
 
namespace itk
{
 
template< class TImage>
void ImageFilter< TImage>
::GenerateData()
{
  double a = 2.1;
  itkExceptionMacro ("Here is a variable: " << a << " and then more text.");
}
 
}// end namespace
 
 
#endif
</source>
 
{{ITKCMakeLists|{{SUBPAGENAME}}}}

Latest revision as of 17:32, 7 June 2019

Warning: The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releases. In many cases, the examples on this page no longer conform to the best practices for modern ITK versions.