1 / 11

ITEC 320

ITEC 320. Lecture 7 Scope Exceptions. Review. Functions Procedures. Outline. Scope Exceptions. No-parameters. procedure demo is procedure printlines is begin put ("------------------"); put ("------------------") ; end printlines ; begin printlines ; -- do something

Télécharger la présentation

ITEC 320

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

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

More Related