Skip to content

fix: replace std::exit with std::invalid_argument in morse_code#3181

Open
https-hari wants to merge 1 commit into
TheAlgorithms:masterfrom
https-hari:fix/morse-exit-to-exception
Open

fix: replace std::exit with std::invalid_argument in morse_code#3181
https-hari wants to merge 1 commit into
TheAlgorithms:masterfrom
https-hari:fix/morse-exit-to-exception

Conversation

@https-hari

Copy link
Copy Markdown

Fixes #3176

Problem

char_to_morse and morse_to_char both called std::exit(0) on invalid
input. This kills the entire process with exit code 0 (success), making
it impossible for callers to handle bad input gracefully via try/catch.

Fix

Replaced both std::exit(0) calls with throw std::invalid_argument(...).
Added #include <stdexcept> accordingly.

Tests

Added two test cases verifying that:

  • char_to_morse throws std::invalid_argument on an unsupported character
  • morse_to_char throws std::invalid_argument on an unrecognised morse string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ciphers/morse_code: char_to_morse/morse_to_char call std::exit(0) on invalid input (library kills caller's process, with success code)

1 participant