+ 2
C++ Challenge question 1
Rearrange the code to define a function "foo", which throws an exception with a value of "-100" if its parameter is greater than 999. Then "foo" catches its exceptions and prints "error!" to the screen. -void foo(int arg) { -if (arg > 999) throw -100; } -} -cout << "error!" << endl; } -try { -catch (int x) {
13 Réponses
+ 7
then the question-creator has specified wrong answer @Sophie
+ 6
the bracket for "if" is facing the wrong way.
not this
if }}
do this
if {}
hope it helps.
+ 5
1,5,2,3,6,4
+ 4
-void foo(int arg) {
-try {
-if (arg > 999) throw -100; }
-catch (int x) {
-cout << "error!" << endl; }
-}
+ 1
I Tried this but it says its worng?
-void foo(int arg) {
-try {
-if (arg > 999) throw -100; }
-}
-catch (int x) {
-cout << "error!" << endl; }
+ 1
the "} " must be at the bottom. the if line already has a closing curly bracket
+ 1
dunno why I got a thumbs down while I answer correctly the question .
so a more verbose answer. @sophie
it's an arrange the code question. look at the if-line. it doesn't open any curly brackets but closes one. if then the next line another curly bracket follows you close the function. this line only containing the curly bracket must therefore be the very last line....
+ 1
try this
void foo(int arg) {
try {
if (arg > 999) throw -100; }
catch (int x) {
cout << "error!" << endl; }
}
0
void foo(int arg) {
try {
if (arg > 999) throw -100; }
catch (int x) {
cout << "error!" << endl; }
}
0
they told ans wrong
0
no result
can help me to solve this problem
0
answer is try, throw, and catch.
0
-void foo(int arg) {
-try {
-if (arg > 999) throw -100; }
-catch (int x) {
-cout << "error!" << endl; }
-}