With all this error talk..

Posted by Jeff Ledbetter on 19-May-2015 13:53

I don't think this is the best coding style for error handling, but am curious. Why doesn't the return value get populated from 'doIt'?  Does the RETURN simply become unreachable code?

DEFINE VARIABLE cError AS CHARACTER NO-UNDO.

RUN doIt.

MESSAGE RETURN-VALUE VIEW-AS ALERT-BOX.

PROCEDURE doIt:

  DEFINE VARIABLE cValue AS CHARACTER NO-UNDO.

  FIND customer NO-LOCK
    WHERE customer.Name = "buttface".

  RETURN cValue.

  CATCH e AS PROGRESS.Lang.SysError:
    cValue = e:getMessage(1).
  END CATCH.

END PROCEDURE.

All Replies

Posted by Peter Judge on 19-May-2015 13:58

Yes.
 
[collapse]
From: Jeff Ledbetter [mailto:bounce-jeffledbetter@community.progress.com]
Sent: Tuesday, 19 May, 2015 14:55
To: TU.OE.Development@community.progress.com
Subject: [Technical Users - OE Development] With all this error talk..
 
Thread created by Jeff Ledbetter

I don't think this is the best coding style for error handling, but am curious. Why doesn't the return value get populated from 'doIt'?  Does the RETURN simply become unreachable code?

DEFINE VARIABLE cError AS CHARACTER NO-UNDO.
 
RUN doIt.
 
MESSAGE RETURN-VALUE VIEW-AS ALERT-BOX.
 
PROCEDURE doIt:
 
  DEFINE VARIABLE cValue AS CHARACTER NO-UNDO.
 
  FIND customer NO-LOCK
    WHERE customer.Name = "buttface".
 
  RETURN cValue.
 
  CATCH e AS PROGRESS.Lang.SysError:
    cValue = e:getMessage(1).
  END CATCH.
 
END PROCEDURE.
Stop receiving emails on this subject.

Flag this post as spam/abuse.

[/collapse]

Posted by Thomas Mercer-Hursh on 19-May-2015 14:06

Slightly less tersely ... when the error occurs, it jumps to the catch, right over the return.

Posted by Jeff Ledbetter on 19-May-2015 14:16

Ok, let’s change it up.
 
Why does this work then? The go4It procedure catches the thrown error, but the RETURN is processed because the main-block get the return-value.
 
 
RUN go4It.
 
MESSAGE RETURN-VALUE VIEW-AS ALERT-BOX TITLE "Main Block".
 
PROCEDURE go4It:
 
  DEFINE VARIABLE cError AS CHARACTER   NO-UNDO.
 
  RUN doIt.
 
  RETURN cError.
 
  CATCH e AS PROGRESS.Lang.AppError:
    cError = e:returnValue.
  END CATCH.
 
END PROCEDURE.
 
PROCEDURE doIt:
 
  DEFINE VARIABLE cValue AS CHARACTER NO-UNDO.
 
  DO ON ERROR UNDO:
 
    FIND customer NO-LOCK
      WHERE customer.Name = "buttface".
 
    CATCH e AS PROGRESS.Lang.SysError:
     cValue = e:getMessage(1).
    END CATCH.
 
  END.
 
  RETURN ERROR cValue.
 
END PROCEDURE.
 
Jeff Ledbetter
skype: jeff.ledbetter
 
[collapse]
From: Thomas Mercer-Hursh [mailto:bounce-tamhas@community.progress.com]
Sent: Tuesday, May 19, 2015 2:07 PM
To: TU.OE.Development@community.progress.com
Subject: RE: [Technical Users - OE Development] With all this error talk..
 
Reply by Thomas Mercer-Hursh

Slightly less tersely ... when the error occurs, it jumps to the catch, right over the return.

Stop receiving emails on this subject.

Flag this post as spam/abuse.

[/collapse]

Posted by Jeff Ledbetter on 19-May-2015 14:24

Never mind. It doesn’t work. The RETURN-VALUE is just left hanging around. Makes more sense now.
 
Jeff Ledbetter
skype: jeff.ledbetter
 
[collapse]
From: Jeff Ledbetter [mailto:bounce-jeffledbetter@community.progress.com]
Sent: Tuesday, May 19, 2015 2:17 PM
To: TU.OE.Development@community.progress.com
Subject: RE: [Technical Users - OE Development] With all this error talk..
 
Reply by Jeff Ledbetter
Ok, let’s change it up.
 
Why does this work then? The go4It procedure catches the thrown error, but the RETURN is processed because the main-block get the return-value.
 
 
RUN go4It.
 
MESSAGE RETURN-VALUE VIEW-AS ALERT-BOX TITLE "Main Block".
 
PROCEDURE go4It:
 
  DEFINE VARIABLE cError AS CHARACTER   NO-UNDO.
 
  RUN doIt.
 
  RETURN cError.
 
  CATCH e AS PROGRESS.Lang.AppError:
    cError = e:returnValue.
  END CATCH.
 
END PROCEDURE.
 
PROCEDURE doIt:
 
  DEFINE VARIABLE cValue AS CHARACTER NO-UNDO.
 
  DO ON ERROR UNDO:
 
    FIND customer NO-LOCK
      WHERE customer.Name = "buttface".
 
    CATCH e AS PROGRESS.Lang.SysError:
     cValue = e:getMessage(1).
    END CATCH.
 
  END.
 
  RETURN ERROR cValue.
 
END PROCEDURE.
 
Jeff Ledbetter
skype: jeff.ledbetter
 
[collapse]
From: Thomas Mercer-Hursh [mailto:bounce-tamhas@community.progress.com]
Sent: Tuesday, May 19, 2015 2:07 PM
To: TU.OE.Development@community.progress.com
Subject: RE: [Technical Users - OE Development] With all this error talk..
 
Reply by Thomas Mercer-Hursh

Slightly less tersely ... when the error occurs, it jumps to the catch, right over the return.

Stop receiving emails on this subject.

Flag this post as spam/abuse.

Stop receiving emails on this subject.

Flag this post as spam/abuse.

[/collapse][/collapse]

Posted by Thomas Mercer-Hursh on 19-May-2015 14:33

I do recommend the little box at the right end of the rich formatting screen for posting code.

Posted by Jeff Ledbetter on 19-May-2015 14:36

I don’t see that little box here in my Outlook client…
 
Jeff Ledbetter
skype: jeff.ledbetter
 
[collapse]
From: Thomas Mercer-Hursh [mailto:bounce-tamhas@community.progress.com]
Sent: Tuesday, May 19, 2015 2:34 PM
To: TU.OE.Development@community.progress.com
Subject: RE: [Technical Users - OE Development] With all this error talk..
 
Reply by Thomas Mercer-Hursh

I do recommend the little box at the right end of the rich formatting screen for posting code.

Stop receiving emails on this subject.

Flag this post as spam/abuse.

[/collapse]

Posted by jmls on 19-May-2015 14:48

that's because you used "buttface" ;)

doing stuff with MyLittlePony would never raise an error ...

Posted by Thomas Mercer-Hursh on 19-May-2015 14:51

Jeff, if you click Use Rich Formatting at the bottom right you get a box with two lines of icons on the top strip.  The rightmost icon on the lower row looks like a square with a pencil in it.  That's the one.  It gives you a box you can past the code into and pick the language.

Posted by Mike Fechner on 19-May-2015 14:54

You got a pony?
Von: jmls [mailto:bounce-jmls@community.progress.com]
Gesendet: Dienstag, 19. Mai 2015 21:49
An: TU.OE.Development@community.progress.com
Betreff: RE: [Technical Users - OE Development] With all this error talk..
 
Reply by jmls

that's because you used "buttface" ;)

doing stuff with MyLittlePony would never raise an error ...

Stop receiving emails on this subject.

Flag this post as spam/abuse.

Posted by Jeff Ledbetter on 19-May-2015 14:55

Yes, I used that the first time. It’s only via the forum UI. My follow up replies have been via email.
 
Jeff Ledbetter
skype: jeff.ledbetter
 
[collapse]
From: Thomas Mercer-Hursh [mailto:bounce-tamhas@community.progress.com]
Sent: Tuesday, May 19, 2015 2:53 PM
To: TU.OE.Development@community.progress.com
Subject: RE: [Technical Users - OE Development] With all this error talk..
 
Reply by Thomas Mercer-Hursh

Jeff, if you click Use Rich Formatting at the bottom right you get a box with two lines of icons on the top strip.  The rightmost icon on the lower row looks like a square with a pencil in it.  That's the one.  It gives you a box you can past the code into and pick the language.

Stop receiving emails on this subject.

Flag this post as spam/abuse.

[/collapse]

Posted by Jeff Ledbetter on 19-May-2015 14:56

Buttface was the cleaned up version..  my lint tool doesn’t allow swear words. ;)
 
Jeff Ledbetter
skype: jeff.ledbetter
 
[collapse]
From: jmls [mailto:bounce-jmls@community.progress.com]
Sent: Tuesday, May 19, 2015 2:49 PM
To: TU.OE.Development@community.progress.com
Subject: RE: [Technical Users - OE Development] With all this error talk..
 
Reply by jmls

that's because you used "buttface" ;)

doing stuff with MyLittlePony would never raise an error ...

Stop receiving emails on this subject.

Flag this post as spam/abuse.

[/collapse]

Posted by Thomas Mercer-Hursh on 19-May-2015 15:03

So, posting code is a good reason not to reply by e-mail ... :)

Posted by Laura Stern on 19-May-2015 22:03

You guys are so entertaining!

Posted by jmls on 20-May-2015 01:20

it was taken away from me ...

Posted by ujj1 on 20-May-2015 09:12

If you put the return cValue in the finally block after the catch, wouldn't you get what you want or were you trying to avoid the finally block? I think there was some issue though where the finally block was not handling returns like this so maybe this only works with 11.x and up.

  DEFINE VARIABLE cValue AS CHARACTER NO-UNDO init 'no-error'.


  FIND customer NO-LOCK

    WHERE customer.Name = "bumface".



  CATCH e AS PROGRESS.Lang.SysError:

    cValue = e:getMessage(1).

  END CATCH.

 finally:
     return cValue.
 end.

Posted by ujj1 on 20-May-2015 09:23

I'm thinking of this:

knowledgebase.progress.com/.../P164717

Different type of issue but good to note.

Posted by Peter Judge on 20-May-2015 09:47

Also note that the behaviour of flow-of-control statements in a FINALLY block changed in 11.4, to be more logical. More info at documentation.progress.com/.../OpenEdge.40.html

This thread is closed