unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Checking parameters
@ 2007-06-17 10:17 Cecil Westerhof
  2007-06-17 10:55 ` Lennart Borgman (gmail)
  2007-06-17 13:18 ` Tim X
  0 siblings, 2 replies; 8+ messages in thread
From: Cecil Westerhof @ 2007-06-17 10:17 UTC (permalink / raw)
  To: help-gnu-emacs

I am new to Emacs and lisp.
What is the best way to check parameters and do error handling when they are
not correct?

I have the following function:
(defun getHours(time)
  (interactive "sHH:MM: ")
  (let ((timelist (split-string time ":")))
    (+
      (string-to-number (car timelist))
      (/
        (string-to-number (cadr timelist))
        60.0
      )
    )
  )
)

How do I check that there is exactly one parameter? And how do I check the
format and give an error that works in interactive and normal mode?
For example when I give
    (getHours "0:120")
I get
    2.0
How should I generate an error/exception?

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-06-18 17:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-17 10:17 Checking parameters Cecil Westerhof
2007-06-17 10:55 ` Lennart Borgman (gmail)
2007-06-17 11:18   ` Lennart Borgman (gmail)
2007-06-17 15:28   ` Nikolaj Schumacher
     [not found]   ` <mailman.2283.1182079099.32220.help-gnu-emacs@gnu.org>
2007-06-17 18:01     ` Cecil Westerhof
2007-06-18 17:27     ` don provan
2007-06-17 13:18 ` Tim X
2007-06-17 18:08   ` Cecil Westerhof

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).