Try Catch not working

I am tring to catch a NilObjectException in the follwoing code…

[code] Try
location.Address = lbContacts.Cell(lbContacts.ListIndex,1)

Catch e As NilObjectException
MsgBox “Not Found. The entered address is probably not valid.”

End Try[/code]

I also tried Catch e As RuntimeException. Neither catch the errror. The app stops with a NilObjectException error on “Location.Address =…” where the error is expected.

What am I doing wrong, or am I not understanding how this works?



OK. I got it. The exception is ignored only if the application is not in debug mode, and in debug mode it continues to the catch code and the app continues to run.


You can toggle Break On Exceptions in Project menu to prevent breaking in debug.
You can even use #pragma BreakOnExceptions false in the method and the setting will only last for that method.

@Massimo Valle Thanks. Learned something new again!