1 / 5

Handling Exceptions in Scheme

CS 480/680 – Comparative Languages. Handling Exceptions in Scheme. exn : not instantiated directly user : raised by calling error variable : unbound global variable at run-time keyword : attempt to change the binding of a global keyword application : not instantiated directly

Download Presentation

Handling Exceptions in Scheme

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. CS 480/680 – Comparative Languages Handling Exceptionsin Scheme

  2. exn : not instantiated directly user : raised by calling error variable : unbound global variable at run-time keyword : attempt to change the binding of a global keyword application : not instantiated directly arity : application with the wrong number of arguments type : wrong argument type to a procedure, not including divide-by-zero mismatch : bad argument combination (e.g., out-of-range index for a vector) or platform-specific integer range error divide-by-zero : divide by zero continuation : attempt to cross a continuation boundary or apply another thread's continuation else : fall-through in cond or case struct : the supertype expression in a struct form returned a value that was not a structure type value object : object-, class-, or interface-specific error unit : unit- or unit/sig-specific error syntax : syntax error, but not a read error read : read parsing error eof : unexpected end-of-file i/o : not instantiated directly port : not instantiated directly read : error reading from a port write : error writing to a port closed : attempt to operate on a closed port user : user-defined input port returned a non-character from the character-getting procedure filesystem : illegal pathname or error manipulating a filesystem object tcp : TCP errors thread : raised by call-with-custodian misc : low-level or MzScheme-specific error unsupported : unsupported feature user-break : asynchronous thread break out-of-memory : out of memory

  3. Catching Exceptions • (with-handlers ( (test? handler) (test? handler) … ) (code)) Macros

  4. Catching Exceptions: Example (define div-w-inf (lambda (n d) (with-handlers ([exn:application:math:zero? (lambda (exn) +inf.0) ] ) (/ n d) ) ) ) Macros

  5. Throwing Excpetions • You can raise your own exception using: (error “error message”) • This raises an exception of type exn:user with the error message you specify • If uncaught, this well exit program execution Macros

More Related