{
  "version": "https://jsonfeed.org/version/1.1",
  "title": "chem-bla-ics",
  "description": "Chemblaics (pronounced chem-bla-ics) is the science that uses open science and computers to solve problems in chemistry, biochemistry and related fields.",
  "home_page_url": "https://chem-bla-ics.linkedchemistry.info/",
  "feed_url": "https://chem-bla-ics.linkedchemistry.info/2010/05/21/cleaner-cdk-code-6-set-cdkexceptions.json",
  "icon": "https://chem-bla-ics.linkedchemistry.info/assets/images/chem-bla-ics_logo.png",
  "language": "en",
  "authors": [
    {
      "name": "Egon Willighagen",
      "url": "https://orcid.org/0000-0001-7542-0286",
      "_orcid": "0000-0001-7542-0286"
    }
  ],
  "items": [

    {
      "id": "https://doi.org/10.59350/mdt9c-fkc91",
      "url": "https://chem-bla-ics.linkedchemistry.info/2010/05/21/cleaner-cdk-code-6-set-cdkexceptions.html",
      "title": "Cleaner CDK Code #6: set the CDKException&apos;s cause Exception",
      "content_html": "<p>For about two weeks now, I am working on fixing a bug in the <em>nonotify</em> module: the classes were still sending around change events.\nI decided to finally do it the proper way: sending around change events is extra functionality, so the data module should extend the\nnonotify module and not the other way around, as in <a href=\"http://cdk.sf.net/\">CDK</a> 1.2 and CDK 1.3 up to now. There was a dirty hack in\nplace, introducing a boolean indicating it should send events or not, but that turned out to be insufficient.</p>\n\n<p>Anyway, while working on a major refactoring like this one, you run into many, many small code issues. Clearly. the one I mostly run\ninto is that a lot of code is not <a href=\"https://chem-bla-ics.linkedchemistry.info/2010/05/15/cleaner-cdk-code-5-developer-against.html\">written against the interfaces yet <i class=\"fa-solid fa-recycle fa-xs\"></i></a>.\nHowever, I just ran into another bit of code that can be improved.</p>\n\n<h3 id=\"set-the-cause-exception-when-throwing-a-cdkexception\">Set the cause Exception when throwing a CDKException</h3>\n\n<p>This is the particular bit of code I ran into:</p>\n\n<div class=\"language-java highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"k\">try</span> <span class=\"o\">{</span>\n  <span class=\"n\">molecule</span> <span class=\"o\">=</span> <span class=\"o\">(</span><span class=\"nc\">IMolecule</span><span class=\"o\">)</span> <span class=\"n\">container</span><span class=\"o\">.</span><span class=\"na\">clone</span><span class=\"o\">();</span>\n<span class=\"o\">}</span> <span class=\"k\">catch</span> <span class=\"o\">(</span><span class=\"nc\">CloneNotSupportedException</span> <span class=\"n\">e</span><span class=\"o\">)</span> <span class=\"o\">{</span>\n  <span class=\"k\">throw</span> <span class=\"k\">new</span> <span class=\"nf\">CDKException</span><span class=\"o\">(</span>\n    <span class=\"s\">\"Error occured during clone \"</span> <span class=\"o\">+</span> <span class=\"n\">e</span>\n  <span class=\"o\">)</span>\n<span class=\"o\">}</span>\n</code></pre></div></div>\n\n<p>However, there are two small improvements that can be applied to this code. The first is that the the error message passed to\nthe CDKException constructor can reuse the <em>message</em> of the cause Exception. The second improvement is that we can actually\npass the cause exception is cause to the CDKException. Therefore, the CDKException can be constructed as (also fixing the typo :):</p>\n\n<div class=\"language-java highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"k\">new</span> <span class=\"nc\">CDKException</span><span class=\"o\">(</span>\n  <span class=\"s\">\"Error occurred during clone \"</span> <span class=\"o\">+</span> <span class=\"n\">e</span><span class=\"o\">.</span><span class=\"na\">getMessage</span><span class=\"o\">(),</span>\n  <span class=\"n\">e</span>\n<span class=\"o\">);</span>\n</code></pre></div></div>\n\n<p>Oh, and, of course, CDK code should use variables of at least three characters. Now, the original CDKException construction was\non one line, in total having <strong><em>four</em></strong> points of improvement :)</p>",
      "summary": "For about two weeks now, I am working on fixing a bug in the nonotify module: the classes were still sending around change events. I decided to finally do it the proper way: sending around change events is extra functionality, so the data module should extend the nonotify module and not the other way around, as in CDK 1.2 and CDK 1.3 up to now. There was a dirty hack in place, introducing a boolean indicating it should send events or not, but that turned out to be insufficient.",
      
      "date_published": "2010-05-21T00:10:00+00:00",
      "date_modified": "2026-07-05T00:00:00+00:00",
      "tags": ["cdk","java"],
      
      
      
      
      
      
        "authors": [ { "name": "Egon Willighagen", "url": "https://orcid.org/0000-0001-7542-0286" } ]
      
    }

  ]
}
