Try Catch never seems to work

I'm aware that try/catch is platform-specific, but for cross-platform code, what good is it? if I can't do something as simple as this..

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>

int main ( void ) {
	
	try {
		int* null=NULL;
		printf("%i",*null); // a NULL dereference
	} catch (...) {
		printf("failed.\n");
	}

	return 0;
}


program Segfaults.
Last edited on
closed account (1yR4jE8b)
You can't catch segfaults, period. Segfaults are the result of undefined behavior and your the operating system, rightfully, takes control and kills the process.
I don't see what's platform-specific about try/catch. The standard clearly states what kind of exceptions is thrown by what functions in what situations.
Topic archived. No new replies allowed.