-
unhandled execption
Hi, i got this program to book seats for a cinema show.if trying to book seats already booked,a exception is thrown.code is as follows.
Code:
try{
if(ifFoundBookedSeats==true){
if(invalidSeatList){
cout<<"\n$$$$$$$$$$$$$$4";
}
cout<<"\nsize"<<invalidSeats.size();
cout<<"\n &"<<invalidSeats[0];
cout<<"\n &"<<invalidSeats[1];
cout<<"\n &"<<invalidSeats[2];
throw SeatsNotFreeException(invalidSeatList,invalidSeats.size());// error line
}
}
catch(SeatsNotFreeException ex){
//try booking alternative seats
// if(ex.bookAlternativeSeats(showSeatList)==true){
// //replace invalid seat numbers with new seat numbers.
// adjustSeatList(seatList,numOfSeats,invalidSeats,ex.getNewValidSeats());
// isSeatsBooked=true;
// }
}
when i run it,it gives me a error: unhandled excpetion at this line "throw SeatsNotFreeException(invalidSeatList,invalidSeats .size());"
when i run it in dev c++... it works fine..no error
run it in microsoft visual compiler.....dang..gives me error !
help !!!!
-
I don't think there is enough information. Have you perhaps disabled exceptions with one compiler and not with the other?
Some notes. Catch exceptions by reference. Generally I don't believe you should throw exceptions if you are going to handle it right there (part of normal program flow).
And tabs mixed with spaces = the indentation mess you can see in the code block.
-
I don't see why that would not work as is. It is sort of odd to see an exception thrown and then caught in the same try/catch block but it is valid. It's no different than calling a function in the try portion that throws on an error condition, however, as has been stated by anon I would recommend you do not throw exceptions if you are going to handle the exception in the same place. You could do the same thing without exceptions using return values.