Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Pavel Markevič
10,402 PointspezAmount in catch part of the code
Hey there,
unreal tutorial. I tried one additional thing - to say how much PEZes is too much (actually it is not a big use of it because user knows what he typed in, but still). So I need to show a message like "%s is too much PEZ" in catch part, so here what I tried:
try {
dispenser.fill(50);
System.out.printf( "%s PEZ overall", dispenser.getPezCount() );
} catch ( IllegalArgumentException iae ) {
System.out.printf("%s is too many PEZ %n", dispenser.pezAmount );
}
but it throws that it can't find pezAmount variable. Probably because of the scope?
So I tried get the pezAmount in the IllegalArgumentException message and then get that message to show in the catch part but it shows
./PezDispenser.java:18: error: incompatible types: int cannot be converted to Throwable
throw new IllegalArgumentException("%d is too many PEZ", pezAmount);
What do You recommend? What is the way? Thanks!
1 Answer
Steve Hunter
57,712 PointsHi Pvael,
Could you post all the code in that file please?
You say that dispenser.pezAmount might be a scope issue; I'd like to see where you create it.
The error you posted suggests you've used a %d in your code somewhere; that's not included in your post.
I'd suggest posting your code. Telling us what it should do and telling us what it is doing that you didn't expect. We may be able to help with that.
Steve.