Exception Handling | Sololearn: Learn to code for FREE!


Exception Handling

anyone could tell me what I am making wrong with the code, because can't pass all of it, just pass 3 of the 4 question . You are making a program to manage user names. A valid username needs to be minimum 4, maximum 20 characters long. Create a program to take a string as input, check its length and output "Valid" if the name is valid, or "Invalid", if it is not. https://code.sololearn.com/ca15A17a7a77


6/10/2021 5:05:49 AM

JRamone MH MarquezH

3 Answers

New Answer


[ "JRamoneMH " ] :: There will be >= 4 and <= 20 if(name.size() >= 4 && name.size() <= 20 ){


thank you Ajanant, I definitely forgot to use my knowledge about the operator. I appreciate it.


The program does not throw an exception implicitly. so there's no reason to try/catch in this type of code. Also, the task requested for a const char* or std: :string output instead you're throwing an exception type The task also required a minimum of 4 and a maximum of 20. This mathematically has the notation off-the-end left inclusive interval, denotated by (4, 20) which means 4 and 20 must be included. So your conditional check should be >= and <= not just >/<