Handling exceptions in scheme
Download
1 / 5

Handling Exceptions in Scheme - PowerPoint PPT Presentation


  • 44 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Handling Exceptions in Scheme' - brenda-wallace


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Handling exceptions in scheme

CS 480/680 – Comparative Languages

Handling Exceptionsin 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

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


Catching exceptions
Catching Exceptions

  • (with-handlers ( (test? handler) (test? handler) … ) (code))

Macros


Catching exceptions example
Catching Exceptions: Example

(define div-w-inf

(lambda (n d)

(with-handlers ([exn:application:math:zero?

(lambda (exn) +inf.0)

]

)

(/ n d)

)

)

)

Macros


Throwing excpetions
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


ad