セクション 4. 章 6
single
Challenge: Refactor Broken Error Handling
メニューを表示するにはスワイプしてください
タスク
スワイプしてコーディングを開始
Refactor a method with tangled error handling so it becomes clear and maintainable. The previous code had multiple nested try-catch blocks, unclear exception handling, and did not validate its arguments properly.
- Throw an
ArgumentExceptioniffilePathis null, empty, or contains only whitespace. - Attempt to read all text from the file at
filePath. - Print the file's content to the console if successful.
- If the file does not exist, catch
FileNotFoundExceptionand print a message including the exception's message. - If access is denied, catch
UnauthorizedAccessExceptionand print a message including the exception's message. - If any other IO error occurs, catch
IOExceptionand print a message including the exception's message.
解答
すべて明確でしたか?
フィードバックありがとうございます!
セクション 4. 章 6
single
AIに質問する
AIに質問する
何でも質問するか、提案された質問の1つを試してチャットを始めてください