Note that there are some explanatory texts on larger screens.

plurals
  1. POException Handling C++ error
    primarykey
    data
    text
    <pre><code>#include&lt;iostream&gt; #include&lt;stdlib.h&gt; #include&lt;string.h&gt; using namespace std; class div { int x,y; public: class dividebyzero { }; class noerror1 { }; div(){}; div(int a,int b) { x=a; y=b; } void error1() { if(y==0) throw dividebyzero(); else throw noerror1(); } int divide() { return (x/y); } }; class naming { char name[32]; public: class nullexception { }; class noerror2 { }; naming(char a[32]) { strcpy(name,a); } void error2() { if(strcmp(name,"")==0) throw nullexception(); else throw noerror2(); } void print() { cout&lt;&lt;"Name-----"&lt;&lt;name&lt;&lt;endl; } }; int main() { div d(12,0); try { d.error1(); } catch(div::dividebyzero) { cout&lt;&lt;"\nDivision by Zero-------Not Possible\n"; } catch(div::noerror1) { cout&lt;&lt;"\nResult="&lt;&lt;d.divide()&lt;&lt;endl; } naming s("Pankaj"); try { s.error2(); } catch(naming::nullexception) { cout&lt;&lt;"\nNull Value in name\n"; } catch(naming::noerror2) { s.print(); } return 0; } </code></pre> <p>On compiling this program I am getting following error </p> <pre><code>pllab55.cpp: In function ‘int main()’: pllab55.cpp:61:6: error: expected ‘;’ before ‘d’ pllab55.cpp:64:3: error: ‘d’ was not declared in this scope pllab55.cpp:72:22: error: ‘d’ was not declared in this scope pllab55.cpp:74:20: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings] </code></pre> <p>Before declaring the class <b>naming</b> everything was running fine.It is after declaration of naming these error started to occur. I am new to C++. Please explain me in details. Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload