Are exceptions standardized in C++? I mean if the rules of exception handling might be changed in the future. i.e: int Funct1(int) throw(); // does it throw an exception?

Member Avatar
Member Avatar
+0 forum 3

Hey Guys, could you tell me the different ways to write throw method (Exception Handling) in a program.. I mean like we can write BufferedReader in many ways (2 ways so far i've studied).. eg; 1. BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 2. BufferedReader br; { br = new BufferedReader(new InputStreamReader(System.in)); }

Member Avatar
Member Avatar
+0 forum 4

Is it mandatory to handle an exception that is thrown using the `throw` keyword? If so is there a separate rule for Checked and Unchecked Exception, as in who should be mandatorily caught? public void met() { throw new ArithmeticException

Member Avatar
Member Avatar
+0 forum 1

Hi, I have read something on IBM's site about exception specification and pointers to functions: void (*f)(); void (*g)(); void (*h)() throw (int); void i() { f = h; // h = g; This is an error. } IBM says: > The compiler allows the assignment f = h because f can throw any kind of exception. The compiler would not allow the assignment h = g because h can only throw objects of type int, while g can throw any kind of exception. But I tested the code in VC++, DEVC++ and CodeBlocks, no error anywhere. Any explanations? Thanks.

Member Avatar
Member Avatar
+0 forum 2

Hi, Is there a way to stop a function from returning a value if a condition evaluates to true. For example my function returns the sum of two integers. How can I stop it from returning anything if one of the integers is negative [CODE] Class C1 { ... public int Sum(int a, int b) { if((a<0)||(b<0)) { trow new Exception(); } else { return a+b; } } }[/CODE] I don't want my program to crash if a or b is negative, but I also don't want the function to return value

Member Avatar
Member Avatar
+0 forum 12

I know it's a good way to catch an exception but why not just make it into a simple if..else statement and run a block of codes then used die to stop the code following it from executing or echo to enable the scripts following it from executing. What's the difference?

Member Avatar
Member Avatar
+1 forum 5

[[CODE]#include <iostream> #include <string> using namespace std; class digits { }; class numOutofRange { }; int string_to_int(string s) throw(digits, numOutofRange); int main() { int histogram[10]; int total; int currentNumber = 0; string s; for(int i=0; i < 10; i++) { histogram[i] = 0; } cout <<"How many numbers do you have to enter? "; cin >> total; while(currentNumber < total) { cout <<"Enter number: " << currentNumber + 1 << " : " << endl; string s; cin >> s; try { int value; //value = string_to_int(s); histogram[value - 1]++; currentNumber++; } catch(numOutofRange) { cout <<"Enter only a number between …

Member Avatar
Member Avatar
+0 forum 3

The End.