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.
throw SeatsNotFreeException(invalidSeatList,invalidSeats.size());// error line
//try booking alternative seats
// //replace invalid seat numbers with new seat numbers.
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 !
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.