@Acer it is saying it is better to throw an error to report problems then it is to use the return type to encode issues.

Follow

@freemo

I am thinking that why the second one can throw error.

@Acer it doesnt actually show you how to throw an exception in the second one. The comment just tells you it does (and references an example of a function which is known to throw system_error).

The function definition in CPP would never indicate directly that it can throw errors. You simply throw the error by calling "throw" inside the function when you write it to make the function throw an error.

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.