help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Checking parameters


From: Cecil Westerhof
Subject: Checking parameters
Date: Sun, 17 Jun 2007 12:17:08 +0200
User-agent: KNode/0.8.0

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?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]