Jeremias Maerki wrote:
Hi Vincent

On 07.01.2009 11:47:16 Vincent Hennebert wrote:
Hi Jeremias,

Author: jeremias
Date: Sun Jan  4 04:59:29 2009
New Revision: 731248
<snip/>
+    /**
+     * Sets the requested encoding mode for this font.
+     * @param mode the new encoding mode
+     */
+    public void setEncodingMode(EncodingMode mode) {
+        if (mode == null) {
+            throw new NullPointerException("mode must not be null");
+        }
+        this.encodingMode = mode;
+    }
<snip/>
         if (type1) {
+            if (encodingMode == EncodingMode.CID) {
+                throw new IllegalArgumentException(
+                        "CID encoding mode not supported for Type 1 fonts");
+            }
I’d rather use assert statements instead. Anything wrong with that?

Nothing, it's a matter of taste. For these cases here, I prefer
exceptions.

No big deal of course, but let me just explain my view of assert vs
exception:
- if the error is due to an illegal use of the library, I use an assert
  and expect the developer to test his program with assertions enabled,
  debug it and then put it in production with assertions disabled. That
  saves some checking overhead.
- if the error is due to some external cause (missing resource, invalid
  URL, etc.) then an exception is to be used.

I don’t know the context, but in this case it seemed to correspond to
the first situation, hence my question.

Vincent

Reply via email to