-
March 29th, 2021, 05:20 AM
#1
Catching OS exceptions
Is there a way to catch exceptions that get generated by the OS? For example...
Code:
try {
fread(NULL, 2, 3, NULL); // This produces an Access Violation error
} catch (...) {
int x = 3; // But we don't seem to reach this line
}
In older versions of VC++ I've a recollection that they offered capitalized versions (i.e. TRY/CATCH) but I'm not too sure if they still exist any more...
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
March 29th, 2021, 07:47 AM
#2
Re: Catching OS exceptions
Last edited by 2kaud; March 29th, 2021 at 07:49 AM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
March 29th, 2021, 09:13 AM
#3
Re: Catching OS exceptions
Many thanks 2kaud - you're probably right about SEH and __try / __except etc.
I tried those suggestions but they don't work here in the case of Access Violations. Instead, the VC debugger gives me this dialog:-
So it looks like certain exceptions just aren't catchable...
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
March 29th, 2021, 11:32 AM
#4
Re: Catching OS exceptions
You might find more info here https://docs.microsoft.com/en-us/win...ption-handling
It seems there are various windows functions that can be used for dealing with exceptions (eg SetUnhandledExceptionFilter). I haven't used them so can't advise further on them.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
March 29th, 2021, 12:20 PM
#5
Re: Catching OS exceptions
The second link in 2kaud's post #2 seems to imply that /EHa might be what you are looking for. I don't have experience with this, either.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|