Skip to content

Commit

Permalink
Merge pull request #22 from SeverinDenisenko/6-add-proper-logging-and…
Browse files Browse the repository at this point in the history
…-error-handling

Add minimal error handling
  • Loading branch information
SeverinDenisenko authored Nov 21, 2024
2 parents 82c42da + 0768fa8 commit 3223643
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions astroimsum/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,32 @@ static void sum_images(array_t<string_t> images)
}
}

int main(int, char* argv[])
int main(int argc, char* argv[])
{
using namespace astro;

string_t reference_image = argv[1];
long images_count = std::stoll(argv[2]);
array_t<string_t> images;
images.push_back(reference_image);
for (long i = 0; i < images_count; ++i) {
images.push_back(argv[3 + i]);
try {
if (argc < 3) {
throw std::runtime_error("Wrong number of arguments");
}

string_t reference_image = argv[1];
long images_count = std::stoll(argv[2]);
array_t<string_t> images;
images.push_back(reference_image);
for (long i = 0; i < images_count; ++i) {
if (argc < i + 4) {
throw std::runtime_error("Wrong number of arguments");
}

images.push_back(argv[3 + i]);
}

sum_images(images);
} catch (const std::exception& ex) {
std::cout << "Error: " << ex.what() << std::endl;
return 1;
}

sum_images(images);

return 0;
}

0 comments on commit 3223643

Please sign in to comment.