core/vidl/vidl_exception.h
Go to the documentation of this file.
00001 // This is core/vidl/vidl_exception.h
00002 #ifndef vidl_exception_h_
00003 #define vidl_exception_h_
00004 //=========================================================================
00005 //:
00006 // \file
00007 // \brief  Exceptions thrown by vidl.
00008 // \author Miguel A. Figueroa-Villanueva (miguelf at ieee dot org)
00009 //
00010 // This file contains a replica of Ian Scott's exception mechanism as
00011 // coded in vil_exception.h and mbl_exception.h. However, it encapsulates
00012 // the exceptions thrown by the vidl library.
00013 //
00014 // Note that vidl_exception_error, vidl_exception_warning, and possibly
00015 // a vxl/vbl_exception should really be part of vbl. So that any level-2
00016 // library can use them.
00017 //
00018 // \verbatim
00019 //  Modifications
00020 //   01/24/2006 - File created. (miguelfv)
00021 //   03/07/2006 - File imported to vxl repository with some modifications
00022 //                and extensions to Paul's code. (miguelfv)
00023 // \endverbatim
00024 //
00025 //=========================================================================
00026 
00027 #include <vcl_iostream.h>
00028 #include <vcl_string.h>
00029 
00030 //-------------------------------------------------------------------------
00031 //: Throw an exception indicating a definite problem.
00032 // If exceptions have been disabled, this function will abort.
00033 //-------------------------------------------------------------------------
00034 template <class T> void vidl_exception_error(T exception)
00035 {
00036   vcl_cerr << "\nERROR: " << exception.what() << vcl_endl;
00037 
00038 #if !defined VIDL_EXCEPTIONS_DISABLE && VCL_HAS_EXCEPTIONS
00039   throw exception;
00040 #else
00041   vcl_abort();
00042 #endif
00043 }
00044 
00045 //-------------------------------------------------------------------------
00046 //: Throw an exception indicating a potential problem.
00047 // If exceptions have been disabled, this function will return.
00048 //-------------------------------------------------------------------------
00049 template <class T> void vidl_exception_warning(T exception)
00050 {
00051   vcl_cerr << "\nWARNING: " << exception.what() << vcl_endl;
00052 
00053 #if !defined VIDL_EXCEPTIONS_DISABLE && VCL_HAS_EXCEPTIONS
00054   throw exception;
00055 #endif
00056 }
00057 
00058 //-------------------------------------------------------------------------
00059 // The list of exceptions.
00060 //-------------------------------------------------------------------------
00061 //: Base class of all vidl exceptions.
00062 class vidl_exception
00063 {
00064  public:
00065   explicit vidl_exception(const vcl_string& msg) : msg_(msg) {}
00066   virtual ~vidl_exception() {}
00067 
00068   virtual const vcl_string& what() const { return msg_; }
00069 
00070  private:
00071   vcl_string msg_;
00072 };
00073 
00074 //: Base class for all the DShow related vidl exceptions.
00075 struct vidl_dshow_exception : public vidl_exception
00076 {
00077   explicit vidl_dshow_exception(const vcl_string& msg)
00078     : vidl_exception("DShow: " + msg) {}
00079 };
00080 
00081 #endif // vidl_exception_h_