From a0d9eeabfa14d374e2eacaf5d835a271e96feae3 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 10 Feb 2023 15:16:44 +0100 Subject: [PATCH] Avoid throwing exception when opening a file for export --- ...ellPathExportCompletionDataFeatureImpl.cpp | 42 ++++++++----------- .../RicWellPathExportCompletionsFileTools.cpp | 12 +----- .../RicWellPathExportCompletionsFileTools.h | 7 ---- 3 files changed, 20 insertions(+), 41 deletions(-) diff --git a/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportCompletionDataFeatureImpl.cpp b/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportCompletionDataFeatureImpl.cpp index 36eb04dd57..1f1bd12c0d 100644 --- a/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportCompletionDataFeatureImpl.cpp +++ b/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportCompletionDataFeatureImpl.cpp @@ -883,15 +883,15 @@ void RicWellPathExportCompletionDataFeatureImpl::sortAndExportCompletionsToFile( if ( !completionsForMainGrid.empty() ) { - try - { - QFileInfo fi( fileName ); - std::shared_ptr exportFile = - RicWellPathExportCompletionsFileTools::openFileForExport( folderName, - fi.baseName(), - fi.suffix(), - exportDataSourceAsComment ); + QFileInfo fi( fileName ); + std::shared_ptr exportFile = + RicWellPathExportCompletionsFileTools::openFileForExport( folderName, + fi.baseName(), + fi.suffix(), + exportDataSourceAsComment ); + if ( exportFile ) + { std::map> completionsForGrid; completionsForGrid.insert( std::pair>( "", completionsForMainGrid ) ); @@ -902,24 +902,21 @@ void RicWellPathExportCompletionDataFeatureImpl::sortAndExportCompletionsToFile( } exportCompdatAndWpimultTables( eclipseCase, exportFile, completionsForGrid, exportType, exportDataSourceAsComment ); } - catch ( RicWellPathExportCompletionsFileTools::OpenFileException ) - { - } } if ( !completionsForSubGrids.empty() ) { - try + QFileInfo fi( fileName ); + + QString lgrFileName = fi.baseName() + "_LGR"; + std::shared_ptr exportFile = + RicWellPathExportCompletionsFileTools::openFileForExport( folderName, + lgrFileName, + fi.suffix(), + exportDataSourceAsComment ); + + if ( exportFile ) { - QFileInfo fi( fileName ); - - QString lgrFileName = fi.baseName() + "_LGR"; - std::shared_ptr exportFile = - RicWellPathExportCompletionsFileTools::openFileForExport( folderName, - lgrFileName, - fi.suffix(), - exportDataSourceAsComment ); - exportWellPathFractureReport( eclipseCase, exportFile, wellPathFractureReportItems ); if ( exportWelspec ) { @@ -927,9 +924,6 @@ void RicWellPathExportCompletionDataFeatureImpl::sortAndExportCompletionsToFile( } exportCompdatAndWpimultTables( eclipseCase, exportFile, completionsForSubGrids, exportType, exportDataSourceAsComment ); } - catch ( RicWellPathExportCompletionsFileTools::OpenFileException ) - { - } } } diff --git a/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportCompletionsFileTools.cpp b/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportCompletionsFileTools.cpp index d50bbdef3f..d412844a96 100644 --- a/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportCompletionsFileTools.cpp +++ b/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportCompletionsFileTools.cpp @@ -33,14 +33,6 @@ #include #include -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RicWellPathExportCompletionsFileTools::OpenFileException::OpenFileException( const QString& message ) - : message( message ) -{ -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -60,7 +52,7 @@ std::shared_ptr RicWellPathExportCompletionsFileTools::openFile( const QS { auto errorMessage = QString( "Selected output folder does not exist, and could not be created." ); RiaLogging::error( errorMessage ); - throw OpenFileException( errorMessage ); + return nullptr; } } @@ -71,7 +63,7 @@ std::shared_ptr RicWellPathExportCompletionsFileTools::openFile( const QS { auto errorMessage = QString( "Export Completions Data: Could not open the file: %1" ).arg( filePath ); RiaLogging::error( errorMessage ); - throw OpenFileException( errorMessage ); + return nullptr; } return exportFile; } diff --git a/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportCompletionsFileTools.h b/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportCompletionsFileTools.h index 7ba0bc023a..04672fe848 100644 --- a/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportCompletionsFileTools.h +++ b/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportCompletionsFileTools.h @@ -28,13 +28,6 @@ class RimWellPath; class RicWellPathExportCompletionsFileTools { public: - class OpenFileException - { - public: - OpenFileException( const QString& message ); - QString message; - }; - static const RimWellPath* findWellPathFromExportName( const QString& wellNameForExport ); static std::shared_ptr