Download
itec 320 n.
Skip this Video
Loading SlideShow in 5 Seconds..
ITEC 320 PowerPoint Presentation

ITEC 320

57 Vues Download Presentation
Télécharger la présentation

ITEC 320

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. ITEC 320 Lecture 7 Scope Exceptions

  2. Review • Functions • Procedures

  3. Outline • Scope • Exceptions

  4. No-parameters procedure demo is procedure printlines is begin put("------------------"); put("------------------"); end printlines; begin printlines; -- do something printlines; end demo;

  5. Global procedure main is MV: constant Natural := 10; subtype MyRange is Integer range 1 .. MV; m1, m2: MyRange; -- procedure p(m: MyRange) is someLocal: Natural; begin ... m1 := 2 * m2; ... end p; procedure q is begin p(3); end q; begin -- main q; end main;

  6. Exceptions • What are they? • Common ones • Data input errors • End of file errors • Constraint errors

  7. Examples procedure demo_exceptions is i: natural; begin get(i); -- do something with i exception when data_error => put_line("found non-numeric input "); when end_error => put_line("end of file reached"); when constraint_error => put_line("integer not a natural"); when others => put_line("integer not a natural"); end demo_exceptions;

  8. Places • Handle everything • Handle specific parts (Add in a begin / end) • Others • Create your own VN:Exception and raise VN • Web example

  9. Problems • Given n of 1 or more, return the factorial of n, which is n * (n-1) * (n-2) ... 1. Compute the result recursively (without loops).

  10. Problem • Given a string, compute recursively (no loops) the number of times lowercase "hi" appears in the string.

  11. Summary • Scope • Exceptions