Throwing exceptions and changing name to a default name
Okay lets say I have a method called setName() and it needs to follow the regex and it cant be empty, if that statement is false, it throws an exception. Once it's false and throws it's exception I want it to turn into a default name for example like "unknown name" but whenever I do and run it only the error exception pops out, would I need to do something in the setName() part or getName() part? I tryed the getName() already and setName(), don't know what I'm doing wrong.
Re: Throwing exceptions and changing name to a default name
Can You show what You tryed?
You can have method called getName(), but not class, since getName() is not valid class definition.
But if You say class getName{}, than it could be class.
Re: Throwing exceptions and changing name to a default name
Re: Throwing exceptions and changing name to a default name
Quote:
Originally Posted by
geforce
Okay lets say I have a method called setName() and it needs to follow the regex
Please explain: what do you mean by "follow the regex"?
Quote:
... and it cant be empty,...
Please explain: what can't be empty? The parameter passed? Something returned from the method?
Quote:
... if that statement is false, it throws an exception.
Please explain: what statement? What do you mean by "is false"?
Quote:
... Once it's false and throws it's exception I want it to turn into a default name for example like "unknown name"
Please explain: turn what into a default name?
Quote:
... but whenever I do and run it only the error exception pops out, would I need to do something in the setName() part or getName() part? I tryed the getName() already and setName(), don't know what I'm doing wrong.
You're asking this question as if we already know a bit about your program and your problem -- but we don't. Please ask a complete question, one with all the information necessary to answer it in the first post if possible.