Re: Try..Except: How?



JamesR wrote:
Well, perhaps crash was the wrong work.. I mean, it causes an error and
stops execution when run under the debugger.. but surely it should
execute the 'except' block?

Yes. And it will, if you tell the debugger to allow your program to continue running. So far, it's just paused at the point of the exception to let you, the developer, inspect the state of your program and determine the error that caused the exception to be raised in the first place.

"But why doesn't the debugger see that I have an 'except' block already and just skip to there?" That's your next question, right?

If the debugger did that, then it would *never* stop on exceptions. *All* code in your program is wrapped in at least one exception handler, often more. When an exception occurs and your program displays a message box with the exception's message, that's a result of TApplication's default exception handler. When a program crashes and the OS displays the "send feedback" dialog, that's as part of the exception handler that gets installed at the base of every program when it starts running.

In this particular case, you can use the TryStrToInt function to avoid the exception altogether.

--
Rob
.



Relevant Pages

  • Re: You wanted defensive writing...
    ... Couldn't you have set the debugger to break on all exceptions? ... > I've created an application that loads Caudill's TreeListView as its ... > I commented the line that called the insertion on start-up, ... > The exception caught me unaware, ...
    (microsoft.public.dotnet.csharp.general)
  • Re: You wanted defensive writing...
    ... Couldn't you have set the debugger to break on all exceptions? ... > I've created an application that loads Caudill's TreeListView as its ... > I commented the line that called the insertion on start-up, ... > The exception caught me unaware, ...
    (microsoft.public.dotnet.general)
  • Re: Problem with KITL?
    ... > Enable kernel debugger ... This OK if KdStub stumbling on its own BP. ... Exception in debugger, Addr=0x801AB864 - attempting to recover ...
    (microsoft.public.windowsce.platbuilder)
  • Re: 64b Windows - crashes not detected
    ... When you have the NULL pointer reference that should trigger an access violation, is it perhaps in a message handler that has come from a SendMessage call? ... a structured exception that would trigger an unwind to an exception handler back into kernel mode will simply be "swallowed" by the OS. ... If I understand you correctly, you are talking only about what gets trapped by the debugger, not what will be caught by exception handlers in your code. ...
    (microsoft.public.vc.mfc)
  • Re: Focus problems on return from dialog ...
    ... You have to tell the DEBUGGER, not the CODE, you are TELLing the code. ... Raising an exception causes the exception dispatcher to go through the ... exception handler by searching the stack frames of the thread in which the ... proceeds backward through preceding stack frames. ...
    (alt.comp.lang.borland-delphi)

Loading