[plt-scheme] exception conventions

From: Neil W. Van Dyke (neil at neilvandyke.org)
Date: Wed Apr 23 01:11:27 EDT 2003

A few questions on using MzScheme exceptions well...

I'm thinking of replacing the copious "error" calls in my HTTP library
with raises of exceptions of the following types:

  (define-struct (exn:httper exn) ())

  (define-struct (exn:httper:protocol-exception exn:httper) ())

  (define-struct (exn:httper:invalid-http-protocol
                  exn:httper:protocol-exception) (detail))
  (define-struct (exn:httper:transport-exception
                  exn:httper:protocol-exception) (sub-exn))

  (define-struct (exn:httper:http-status-check-exception
                 (status-code phrase))

1. For "exn:httper:transport-error", I'm thinking of having the library
   catch some exceptions from the TCP, SSL, or other lower-level
   protocol libraries, and wrap them up in the more abstract exception.
   I suspect fitting these foreign exceptions into the library-specific
   abstraction hierarchy will make it easier for users of the library.
   Is this frowned upon?

2. Are there any problems with putting a caught exception into a
   "sub-exn" field of an exception struct that is then itself raised?
   For example, does it break any debugging-related code, or introduce
   inefficiencies in the implementation of exception raises?

3. Is naming exception structures beginning with "exn:" followed by the
   package name ("httper") like this the way to go?  Or should I use
   names like "httper-exception", "httper-protocol-exception",
   "invalid-http-exception", "http-transport-error", and
   "http-status-check-error"?  Or something else?

4. Other comments?

P.S., No criticism of collects/net/url.ss is intended by writing my own
      HTTP library.  Coding from scratch is a good exercise as I figure
      out exactly what features my picky applications need.  After a few
      applications, hopefully I can make good suggestions on
      enhancements to url.ss, and possibly merge some code in.


Posted on the users mailing list.