Exceptions

I am working on a hardware inventory, using struct and reading the file to a vector.
I also sort and merge two files together.

My question is where would it be best to throw an exeption,
not very familiar with throw, try & catch
?? You throw an exception if you encounter an error or a situation considered incorrect by your program. Usually you throw an exception when your program cannot continue for whatever reason.
Generally, you put a try before anything that has to be converted, such as you have some user input that has to converted to a numeric value. For files, you'd want to put it before you do anything with the file really. That way, if you try to read a file that doesn't exist, then your program wont just crash. There's lots of places you'll find to stick these, but just think. If something CAN go wrong, then you should stick it in a try block
Topic archived. No new replies allowed.