Is it possible to use exceptions with file opening as an alternative to using .is_open()?
For example:
ifstream input;
try{
input.open("somefile.txt");
}catch(someException){
//Catch exception here
}
If so, what type is someException?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
http://en.cppreference.com/w/cpp/io/basic_ios/exceptions
Also read this answer 11085151 which references this article
Sample code running on Wandbox
EDIT: catch exceptions by const reference 2145147
EDIT: removed failbit from the exception set. Added URLs to better answers.