Would someone explain Try-Except to me? Microsoft is being confusing. I understand the basic idea (I understand Try-Catch), but I don't really get what the expression in __except([expression]) is for. Also, what's __finally for, and when is it executed? Thank you!
Try-Except/Finally?
Started by RobotGymnast, Sep 05 2009 08:03 PM
6 replies to this topic
#1
Posted 05 September 2009 - 08:03 PM
|
|
|
#2
Posted 05 September 2009 - 08:13 PM
As far as I can read, __Try-__Except works precisely the same way as "Try-Catch" does, it's just that Microsoft added that extension for use in the C language. If you're going to be programming in C++, just use the native Try-Catch system of exception handling, since that will work on more than just Windows and is supported by all compilers.
__finally is the same as Finally in C++ exception handling as well, it's executed at the end of the try block whether or not an exception was thrown. It's usually used to handle dynamically allocated memory.
__finally is the same as Finally in C++ exception handling as well, it's executed at the end of the try block whether or not an exception was thrown. It's usually used to handle dynamically allocated memory.
Wow I changed my sig!
#3
Posted 05 September 2009 - 08:14 PM
Okay, that makes sense.
The reason I'm using __try __except is because I'm hoping to catch access violations.
The reason I'm using __try __except is because I'm hoping to catch access violations.
#4
Posted 05 September 2009 - 08:16 PM
Have you tried this:
try {
// Statement that throws access violation
} catch (...) {
std::cout << "Access violation thrown!" << std::endl;
}
Just checking?
Wow I changed my sig!
#5
Posted 05 September 2009 - 08:17 PM
yup.
#6
Posted 05 September 2009 - 08:18 PM
Does the access violating code return some kind of signal that you know of at all?
EDIT: And, could you give me a small example of how this is being used, so that I can help troubleshoot it? I understand proprietary and stuff, but just a small example of the input you receive, how you give the input to the assembly call, then what variable the output is applied to should be sufficient.
EDIT: And, could you give me a small example of how this is being used, so that I can help troubleshoot it? I understand proprietary and stuff, but just a small example of the input you receive, how you give the input to the assembly call, then what variable the output is applied to should be sufficient.
Wow I changed my sig!
#7
Posted 05 September 2009 - 08:23 PM
Depends what you mean by "signal". Access violations are caught by debuggers, but other than that, no checks/handling is performed by the function.
__try __except works perfectly. Thanks!
__try __except works perfectly. Thanks!


Sign In
Create Account


Back to top









