tException.h
Go to the documentation of this file.
00001 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00002 // This file is part of FZIs ic_workspace.
00003 //
00004 // This program is free software licensed under the LGPL
00005 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00006 // You can find a copy of this license in LICENSE folder in the top
00007 // directory of the source code.
00008 //
00009 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00010 //
00011 // -- END LICENSE BLOCK ------------------------------------------------
00012 
00013 // ----------------------------------------------------------
00014 /*
00015  * tException
00016  * icl_hardware
00017  *
00018  * Created by Hugo Ritzkowski on 2012-02-07.
00019  * Copyright 2012
00020  * Company Forschungszentrum Informatik (FZI), Abteilung IDS.
00021  * All rights reserved.
00022  *
00023  */
00024 // ----------------------------------------------------------
00033 // ----------------------------------------------------------
00034 
00035 #ifndef ICL_HARDWARE_TEXCEPTION_H
00036 #define ICL_HARDWARE_TEXCEPTION_H
00037 
00038 #include <string>
00039 #include <exception>
00040 
00041 namespace icl_hardware
00042 {
00043 namespace can
00044 {
00046 enum Hardware_Exception
00047 {
00048   eHARDWARE_ERROR,
00049   ePEAK_DEVICE_ERROR,
00050   eTHREAD_ERROR,
00051   eMESSAGE_ERROR,
00052   eFILE_ERROR
00053 };
00054 
00055 class tException : public std::exception
00056 {
00057 public:
00059   tException(Hardware_Exception exception, const std::string &_description)
00060     : description(_description),
00061       error_code(exception)
00062   {};
00063 
00065   tException(Hardware_Exception exception)
00066     : error_code(exception)
00067   {
00068     switch(exception)
00069     {
00070     case eHARDWARE_ERROR:
00071     {
00072       this->description = "Hardware error.";
00073       break;
00074     }
00075     case ePEAK_DEVICE_ERROR:
00076     {
00077       this->description = "Problem with Peak-Can-Device.";
00078       break;
00079     }
00080     case eTHREAD_ERROR:
00081     {
00082       this->description = "Thread unscheduled terminated.";
00083     }
00084     case eMESSAGE_ERROR:
00085     {
00086       this->description = "Empty message received.";
00087     }
00088     case eFILE_ERROR:
00089     {
00090       this->description = "Error while writing to file.";
00091     }
00092     }
00093   };
00094 
00096   ~tException() throw()
00097   {};
00098 
00100   virtual const char* what() const throw()
00101   {
00102     return description.c_str();
00103   }
00104 
00106   inline std::string GetDescription()
00107   {
00108     return description;
00109   };
00110 
00112   inline Hardware_Exception GetErrorCode()
00113   {
00114     return error_code;
00115   };
00116 
00117 protected:
00119   std::string description;
00120 
00122   Hardware_Exception error_code;
00123 };
00124 } /* can */
00125 } /* icl_hardware */
00126 #endif // ICL_HARDWARE_TEXCEPTION_H


fzi_icl_can
Author(s):
autogenerated on Tue Aug 8 2017 03:07:51