My first TRY block

Discussion in 'Mac Programming' started by Maury, Aug 1, 2012.

  1. Maury, Aug 1, 2012
    Last edited by a moderator: Aug 4, 2012

    Maury macrumors 6502

    Mar 25, 2008
    Consider this ODBC 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?
  2. jared_kipe, Aug 1, 2012
    Last edited by a moderator: Aug 4, 2012

    jared_kipe macrumors 68030


    Dec 8, 2003
    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?

Share This Page