From: Anthony Geay Date: Fri, 19 Jan 2018 07:29:18 +0000 (+0100) Subject: Keep PARAVIS alive after exception thrown on writing X-Git-Tag: V8_5_0a1~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c03eb35a70f1bfaca8112a22d81b358c42e3d0b8;p=modules%2Fparavis.git Keep PARAVIS alive after exception thrown on writing --- diff --git a/src/Plugins/MEDWriter/IO/VTKToMEDMem.cxx b/src/Plugins/MEDWriter/IO/VTKToMEDMem.cxx index b6398958..8b295481 100644 --- a/src/Plugins/MEDWriter/IO/VTKToMEDMem.cxx +++ b/src/Plugins/MEDWriter/IO/VTKToMEDMem.cxx @@ -664,7 +664,16 @@ void ConvertFromPolyData(MEDFileData *ret, vtkPolyData *ds, const std::vectorGetLines()); if(cc) { - MCAuto subMesh(BuildMeshFromCellArray(cc,coords,1,INTERP_KERNEL::NORM_SEG2)); + MCAuto subMesh; + try + { + subMesh=BuildMeshFromCellArray(cc,coords,1,INTERP_KERNEL::NORM_SEG2); + } + catch(INTERP_KERNEL::Exception& e) + { + std::ostringstream oss; oss << "MEDWriter does not manage polyline cell type because MED file format does not support it ! Maybe it is the source of the problem ? The cause of this exception was " << e.what() << std::endl; + throw INTERP_KERNEL::Exception(oss.str()); + } if((const MEDCouplingUMesh *)subMesh) { std::vector > cellFs(AddPartFields2(offset,offset+subMesh->getNumberOfCells(),ds->GetCellData())); diff --git a/src/Plugins/MEDWriter/IO/vtkMEDWriter.cxx b/src/Plugins/MEDWriter/IO/vtkMEDWriter.cxx index 65537b3e..4c6cd3ef 100644 --- a/src/Plugins/MEDWriter/IO/vtkMEDWriter.cxx +++ b/src/Plugins/MEDWriter/IO/vtkMEDWriter.cxx @@ -212,6 +212,18 @@ int vtkMEDWriter::RequestUpdateExtent(vtkInformation* vtkNotUsed(request), vtkIn return 1; } +template +void ExceptionDisplayer(vtkMEDWriter *self, const std::string& fileName, T& e) +{ + std::ostringstream oss; + oss << "Exception has been thrown in vtkMEDWriter::RequestData : During writing of \"" << fileName << "\", the following exception has been thrown : "<< e.what() << std::endl; + if(self->HasObserver("ErrorEvent") ) + self->InvokeEvent("ErrorEvent",const_cast(oss.str().c_str())); + else + vtkOutputWindowDisplayErrorText(const_cast(oss.str().c_str())); + vtkObject::BreakOnError(); +} + int vtkMEDWriter::RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) { //std::cerr << "########################################## vtkMEDWriter::RequestData ########################################## " << (const char *) this->FileName << std::endl; @@ -269,15 +281,14 @@ int vtkMEDWriter::RequestData(vtkInformation *request, vtkInformationVector **in } } } + catch(INTERP_KERNEL::Exception& e) + { + ExceptionDisplayer(this,(const char *) this->FileName,e); + return 0; + } catch(MZCException& e) { - std::ostringstream oss; - oss << "Exception has been thrown in vtkMEDWriter::RequestData : During writing of \"" << (const char *) this->FileName << "\", the following exception has been thrown : "<< e.what() << std::endl; - if(this->HasObserver("ErrorEvent") ) - this->InvokeEvent("ErrorEvent",const_cast(oss.str().c_str())); - else - vtkOutputWindowDisplayErrorText(const_cast(oss.str().c_str())); - vtkObject::BreakOnError(); + ExceptionDisplayer(this,(const char *) this->FileName,e); return 0; } return 1;