Domino 9 und frühere Versionen > ND6: Entwicklung

error handling

(1/2) > >>

littleS:
Hallo,

macht das zweite "Exit Sub" Sinn?


--- Code: ---Sub SubName
  On Error Goto myerrhandler
 
  .....

  Exit Sub
myerrhandler:
  MessageBox "frmTest SubName(): " & Erl & ": " & Error$
  Exit Sub  '// <-- macht das Exit Sub Sinn?
End Sub

--- Ende Code ---

Semeaphoros:
Wenn man strukturierte Programmierung streng anwendet, müsste man mit einem Resume vor das eigengliche Exit Sub springen und wenn die Sub auch wirklich gut pflegbar sein soll, würde ich das auch so machen (sprich es gibt genau ein einziges Exit Sub). Dann bleiben eventuell notwendige Endverarbeitungen, die auch im Fehlerfall durchgeführt werden müssen, sicher an einem Ort und werden nicht vergessen.

Marinero Atlántico:
Hi,

ich stimme mit Jens nicht überein.
Für meinen Geschmack ist das 2. Exit Sub völlig in Ordnung.
Die Intention der Vorgabe nicht mehrere Ausstiegspunkte aus einer Subroutine zu haben, liegt darin, dass es sehr verwirrend sein kann, besagte Ausstiegspunkte zu finden.
Wenn man das eine KOnvention für Errorhandling macht (das 2. Exit Sub), dann ist das für meinen Geschmack eine Konvention, die völlig in Ordnung ist.
Die Intention von Designrichtlinien sind imho wichtiger als fragwürdige, starre Regeln.

Hier ein satirischer Beitrag des einzigartigen H. Suleiman, über Compiler, die anhand von zu starren Designrichtlinien Meldungen abgeben, die keine Fehler sind:

--- Zitat ---Foolishly, I upgraded to jikes 1.21. Every time I compile now, I want to immolate those chocolate log miners. I am filled with such rage, such fury, that no punishment or torture method seems severe enough to slake my thirst for revenge and retribution.

Why in god's name do I need to be informed, by default, of every time I use a local variable to shadow a member field? Why can't I not specify a break in my switch statements if I so choose? The language allows both and has VERY explicit clear rules about what happens and how it's treated. If it's good enough for the goddam JLS, it's good enough for me. You, jikes twats, have NO right deciding my coding habits for me. You're a bunch of fuckwitted angsty IBMers who think that all they need to do is tug some linux/OSS penis to be admired and loved by all.

It's one thing to write a custom compiler for children just taking their first java steps. It's quite another to foist this disgusting filth onto people who supposedly know what they're doing. I mean, we can forgive the fact that it emits different bytecode to javac (look at the code generated for asserts, for example), we can forgive the fact that its website is one of the most difficult to navigate or find any info at, but really, even us seasoned bitter cynics have our limits.

--- Ende Zitat ---
http://www.jroller.com/page/fate/?anchor=jikes_authors_are_terrorists
Axel

Semeaphoros:
As you like, Axel, ich hab das bewusst nicht so formuliert, dass man mir glauben muss ....  ;)

Trotzdem, wenn Du das Exception - Handling in jüngeren Sprachen wie Java oder auch Delphi-Pascal ansiehst, wirst Du finden, dass dort genau für das von mir angetönte Problem eine Lösung zur Verfügung gestellt wird: Code, der ausgeführt wird unabhängig davon, ob ein Fehler auftrat oder nicht, und genau zur Sicherstellung, dass das auch klappt, macht die "nurEinExitPunkt" Strategie eben Sinn, es sei denn, der Compiler beherrscht das, so wie bei einem Ojekt der Destruktor, den gibts aber bei einer Sub nicht.

littleS:
Hallo,

danke erstmal. So weit hatte ich das ganze nicht durchdacht, mir ging es erstmal darum, ob ein "Exit Sub" notwendig ist, wenn direkt danach ein "End Sub" kommt. Welcher Unterschied besteht denn zwischen

--- Code: ---  Exit Sub  <-- Funktion läuft fehlerfrei durch und wird hier verlassen !?
myerrhandler:
...
End Sub

--- Ende Code ---
und

--- Code: ---  Exit Sub
myerrhandler:
  MessageBox ...
  Exit Sub <-- Fehler trat auf und Sub wird hier verlassen
End Sub

--- Ende Code ---
bzw.

--- Code: ---  Exit Sub
myerrhandler:
  MessageBox...
End Sub  <-- Fehler trat auf und sub wird hier verlassen

--- Ende Code ---



s.

Navigation

[0] Themen-Index

[#] Nächste Seite

Zur normalen Ansicht wechseln