Try Catch never seems to work

Brandon Captain (18)
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
darkestfright (1089)
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.
Peter87 (3687)
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.
Registered users can post here. Sign in or register to post.