Weird #pragma behaviour

I’ve well tested library. Today, I added several #pragma in every function to speed up the execution time. I found a weird behaviour.

This code works well.

Try
    #Pragma BreakOnExceptions False

    dim c as Class1
    MsgBox c.txt

Catch
End Try

But, after added this code

If Not DebugBuild Then
    #Pragma NilObjectChecking False
    #Pragma DisableBoundsChecking
    #Pragma StackOverflowChecking False
End If

Try
    #Pragma BreakOnExceptions False

    dim c as Class1
    MsgBox c.txt

Catch
End Try

I got Segmentation fault. I can’t even run unit testing completely. So, I’m thinking to remove the added #pragma, but just out of curiosity, is this a well known bug? is there a workaround about this?

Note:
The code is just an example.

I think

If Not DebugBuild Then #Pragma NilObjectChecking False #Pragma DisableBoundsChecking #Pragma StackOverflowChecking False End If
needs to be

#if not DebugBuild then #Pragma NilObjectChecking False #Pragma DisableBoundsChecking #Pragma StackOverflowChecking False #endif

Aside from Tim’s observation, these pragmas should be used with care and sparingly as they will prevent exceptions that would normally be raised. In the case of your code, you would normally get a NilObjectException because you did not instantiate c, but the pragma prevents that and you crash hard instead. So yes, you might get a speed boost, but you sacrifice the safety net of the normal error-trapping mechanisms.

BTW, be sure to follow up BreakOnExceptions False with BreakOnExceptions Default.

Thank you Tim, how could I miss that?

I see. That’s why Try...Catch doesn’t work.