Skip to content

Commit b7c8663

Browse files
authored
Merge pull request #4672 from jjimenezshaw/catch-in-projinfo
Add try/catch in projinfo
2 parents 28b72af + 3fde63e commit b7c8663

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/apps/projinfo_lib.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,11 +1004,11 @@ static int outputOperations(
10041004
promoteTo3D, normalizeAxisOrder, outputOpt.quiet, strm);
10051005
if (!sourceObj.has_value())
10061006
return 1;
1007-
auto sourceCRS = nn_dynamic_pointer_cast<CRS>(*sourceObj);
1007+
auto sourceCRS = nn_dynamic_pointer_cast<CRS>(sourceObj.value());
10081008
CoordinateMetadataPtr sourceCoordinateMetadata;
10091009
if (!sourceCRS) {
10101010
sourceCoordinateMetadata =
1011-
nn_dynamic_pointer_cast<CoordinateMetadata>(*sourceObj);
1011+
nn_dynamic_pointer_cast<CoordinateMetadata>(sourceObj.value());
10121012
if (!sourceCoordinateMetadata) {
10131013
strm.cerr
10141014
<< "source CRS string is not a CRS or a CoordinateMetadata"
@@ -1027,11 +1027,11 @@ static int outputOperations(
10271027
promoteTo3D, normalizeAxisOrder, outputOpt.quiet, strm);
10281028
if (!targetObj.has_value())
10291029
return 1;
1030-
auto targetCRS = nn_dynamic_pointer_cast<CRS>(*targetObj);
1030+
auto targetCRS = nn_dynamic_pointer_cast<CRS>(targetObj.value());
10311031
CoordinateMetadataPtr targetCoordinateMetadata;
10321032
if (!targetCRS) {
10331033
targetCoordinateMetadata =
1034-
nn_dynamic_pointer_cast<CoordinateMetadata>(*targetObj);
1034+
nn_dynamic_pointer_cast<CoordinateMetadata>(targetObj.value());
10351035
if (!targetCoordinateMetadata) {
10361036
strm.cerr
10371037
<< "target CRS string is not a CRS or a CoordinateMetadata"
@@ -2112,9 +2112,9 @@ static int main_projinfo(PJ_CONTEXT *ctx, int argc, char **argv,
21122112
dbContext, user_string, std::string(), objectKind,
21132113
"input string", buildBoundCRSToWGS84, allowUseIntermediateCRS,
21142114
promoteTo3D, normalizeAxisOrder, outputOpt.quiet, strm));
2115-
if (!obj_opt)
2115+
if (!obj_opt.has_value())
21162116
return 1;
2117-
auto obj = *obj_opt;
2117+
auto obj = obj_opt.value();
21182118
if (guessDialect) {
21192119
auto dialect = WKTParser().guessDialect(user_string);
21202120
strm.cout << "Guessed WKT dialect: ";
@@ -2234,9 +2234,13 @@ static int main_projinfo(PJ_CONTEXT *ctx, int argc, char **argv,
22342234

22352235
int projinfo(PJ_CONTEXT *ctx, int argc, char **argv, projinfo_cb_t callback,
22362236
void *user_data) {
2237-
2238-
Streamer strm(callback, user_data);
2239-
return main_projinfo(ctx, argc, argv, strm);
2237+
try {
2238+
Streamer strm(callback, user_data);
2239+
return main_projinfo(ctx, argc, argv, strm);
2240+
} catch (const std::exception &e) {
2241+
pj_log(ctx, PJ_LOG_ERROR, "Unexpected exception: %s", e.what());
2242+
}
2243+
return 1;
22402244
}
22412245

22422246
//! @endcond

0 commit comments

Comments
 (0)