/*============================================================================= NOTE: THIS FILE IS A HANDMADE WRAPPER FOR THE ManagedITK PROJECT. Project: ManagedITK Program: Insight Segmentation & Registration Toolkit Module: itkManagedExceptionObject.cxx Language: C++/CLI Author: Dan Mueller Date: $Date: 2007-09-01 06:17:25 +1000 (Sat, 01 Sep 2007) $ Revision: $Revision: 2 $ Copyright (c) Queensland University of Technology (QUT) 2007. All rights reserved. Portions of this code are covered under the ITK and VTK copyright. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =============================================================================*/ #pragma once #pragma warning( disable : 4635 ) // Disable warnings about XML doc comments #ifndef __itkManagedExceptionObject_cxx #define __itkManagedExceptionObject_cxx // Include some ITK files #pragma unmanaged #include "itkExceptionObject.h" // Use some managed namespaces #pragma managed #using #using using namespace System; using namespace System::IO; using namespace System::Reflection; using namespace System::ComponentModel; using namespace System::Diagnostics; namespace itk { /// ///A managed wrapper for itk::ExceptionObjects. /// public ref class itkExceptionObject : System::ApplicationException { private: System::String^ m_Description; System::String^ m_Location; System::String^ m_File; unsigned int m_Line; public: ///Constructor taking a native itk::ExceptionObject. ///The native itk::ExceptionObject. itkExceptionObject ( itk::ExceptionObject& ex ) : System::ApplicationException( gcnew System::String( ex.GetDescription() ) ) { this->m_Description = gcnew System::String( ex.GetDescription() ); this->m_Location = gcnew System::String( ex.GetLocation() ); this->m_File = gcnew System::String( ex.GetFile() ); this->m_Line = ex.GetLine(); } ///Constructor taking managed components. ///The native exception description. ///The native exception location. ///The file the naive exception was raised from. ///The line the naive exception was raised from. itkExceptionObject ( System::String^ desc, System::String^ loc, System::String^ file, unsigned int line ) : System::ApplicationException( desc ) { this->m_Description = desc; this->m_Location = loc; this->m_File = file; this->m_Line = line; } ///Constructor taking std::string components. ///The native exception description. ///The native exception location. ///The file the naive exception was raised from. ///The line the naive exception was raised from. itkExceptionObject ( const char* desc, const char* loc, const char* file, unsigned int line ) : System::ApplicationException( gcnew System::String( desc ) ) { this->m_Description = gcnew System::String( desc ); this->m_Location = gcnew System::String( loc ); this->m_File = gcnew System::String( file ); this->m_Line = line; } ///Gets the description. This is the same as the Message. property System::String^ Description { virtual System::String^ get() { return this->m_Description; } } ///Gets the method location where the exception was thrown. property System::String^ Location { virtual System::String^ get() { return this->m_Location; } } ///Gets the name of the source ode file from which the exception was thrown. property System::String^ File { virtual System::String^ get() { return this->m_File; } } ///Gets the name of the source ode file from which the exception was thrown. property unsigned int Line { virtual unsigned int get() { return this->m_Line; } } ///Returns a string representation of the itkExceptionObject. ///A string representation similar the native itk::ExceptionObject::Print() method. virtual String^ ToString() override { System::String^ result = String::Empty; result += this->Message; if (this->m_Location->Length > 0) result += Environment::NewLine + "Location: " + this->m_Location; if (this->m_File->Length > 0) { result += Environment::NewLine + "File: " + this->m_File; result += Environment::NewLine + "Line: " + this->m_Line; } if (this->StackTrace != nullptr && this->StackTrace->Length > 0) result += Environment::NewLine + this->StackTrace; return result; } }; // end ref class } // end namespace itk #endif