Sorry, but the traditional way to do this is to read "errno" (Linux) or WSAGetLastError () (Windows) at the time of error (i.e. when your "connect()" fails; presumably returning "-1").
This is true for all the socket calls ("socket()", "accept()", "setsockopt ()", etc etc).
I suspect the problem here is that, because the "connect()" failed, you don't actually have a socket and there's nothing for "getsockopt ( SO_ERROR )" to return.
But I'm not sure under what circumstances you can legitimately call "getsockopt ( SO_ERROR )", or how portable this approach is. There's really no easy way to adapt a "try/catch" style of programming without writing your own wrapper classes (or using somebody else's OO socket wrappers).
I would definitely encourage you to simply check for (and respond to) errors at the point of call. I would also encourage you to become thoroughly comfortable with "procedural sockets", even if you do ultimately wind up using a higher-level, OO library. Here are two excellent references:
http://beej.us/guide/bgnet/
Stevens, Unix Network Programming (3rd Ed):
http://www.amazon.com/Unix-Network-P...dp/0131411551/
IMHO .. PSM