+ 1

How to make a multiple exceptions in integer

the program get two values from the user , if v1 less than 0 than throw an exception .. and if v2 is bigger than 50 it will throw an exception , I want any exception have a different catches with integer , but I don't how to do that !

27th Nov 2017, 11:43 AM
mass com
mass com - avatar
2 Respostas
+ 5
try { int v1,v2; cin>>v1>>v2; if(v1<0) throw 1; if(v2>50) throw 2; } catch(int s) { switch(s) { case 1: cout<<"Less than 0"; break; case 2: cout<<"More than 50"; break; } }
27th Nov 2017, 1:05 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 1
thanks a lot 😊
27th Nov 2017, 1:28 PM
mass com
mass com - avatar