Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Maury

macrumors 6502
Original poster
Mar 25, 2008
456
26
Consider this ODBC code...
Code:
nResult = SQLConnect(hdbc,
(UCHAR *)[dsn cStringUsingEncoding:defaultEncoding], SQL_NTS,
(UCHAR *)[userName cStringUsingEncoding:defaultEncoding], SQL_NTS,
(UCHAR *)[password cStringUsingEncoding:defaultEncoding], SQL_NTS);
	
// if failed to connect, free the allocated hdbc before return	
if (nResult != SQL_SUCCESS && nResult != SQL_SUCCESS_WITH_INFO) {
	[self logError:nResult forStatement:SQL_NULL_HSTMT];
	SQLFreeHandle(SQL_HANDLE_DBC, hdbc); 
	return NO;
}
The problem I'm having is that some ODBC drivers are poorly written, and SQLConnect simply dies with a BAD_EXEC.

I'd like to wrap this in a try block, which should flow through into the following IF.

Is the best solution to set a bool and read it in the IF, or is there a better style?
 
Last edited by a moderator:

jared_kipe

macrumors 68030
Dec 8, 2003
2,967
1
Seattle
I'd like to wrap this in a try block, which should flow through into the following IF.

Is the best solution to set a bool and read it in the IF, or is there a better style?

Unfortunately try will not help you in this example. BAD_EXEC is from something like dereferencing a null pointer and cannot be intercepted. (@try relies on exceptions being thrown, not just generic memory faults)

Are you sure that the BAD_EXEC isn't from something you've written?
 
Last edited by a moderator:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.