hello everyone. when working with objects, how would one specify that the input of negative numbers is not allowed in the constructor part of the code?
shroomiin 0 Light Poster
Recommended Answers
Jump to Postyou are getting that error because in your constructor part you specified that an Exception is thrown therefor any calls to that exception must handle that thrown Exception.
To solve that problem surround your code with a try - catch clause
try{ c1 = new CircleObj(inputx,inputy,inputradius); …
Jump to Postdeclare your c1 variable outside the try catch and initialize it with a null value ..something like
CircleObj c1 = null; try{ c1 = new CircleObj(inputx,inputy,inputradius); }catch(Exception ex){ //put some error messages here or any error handlers }
Note: Anything you declare inside the try-catch is a …
All 5 Replies
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
shroomiin 0 Light Poster
Jocamps 14 Junior Poster
shroomiin 0 Light Poster
Jocamps 14 Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.