Bug 47171 - Should never use Error to report runtime errors
Summary: Should never use Error to report runtime errors
Status: NEW
Alias: None
Product: Batik - Now in Jira
Classification: Unclassified
Component: GVT (show other bugs)
Version: 1.7
Hardware: PC Windows XP
: P2 normal
Target Milestone: ---
Assignee: Batik Developer's Mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-08 15:57 UTC by Sebb
Modified: 2009-05-09 03:09 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sebb 2009-05-08 15:57:11 UTC
TIFFImageEncoder uses Error to report unexpected conditions, e.g.

        switch(dataType) {
        case DataBuffer.TYPE_BYTE:
            if(sampleSize[0] != 1 && sampleSize[0] == 4 &&
               sampleSize[0] != 8) {
                throw new Error("TIFFImageEncoder2");
            }
            break;

Using Error makes it hard to safely catch the exception, as there are some Errors that should not be caught (e.g. ThreadDeath)

The code should use a more specific Error, e.g. RuntimeException or IllegalArgumentException or InvalidParameterException.

There are over 70 classes where Error is thrown - please can these be changed to something more appropriate?
Comment 1 Helder Magalhães 2009-05-09 00:19:46 UTC
(In reply to comment #0)
> TIFFImageEncoder uses Error to report unexpected conditions, e.g.

Although not very familiar with this, regarding this specific class I'd say there's pending effort into using XML Graphics Commons [1] for the task (this implementation should be abandoned in favor of a more compatible one (see bug 38183 and bug 46513).


> Using Error makes it hard to safely catch the exception, as there are some
> Errors that should not be caught (e.g. ThreadDeath)
[...]
> There are over 70 classes where Error is thrown [...]

I haven't dig up on this enough but, for what it's worth, I'd vote on this also. :-)


[1] http://xmlgraphics.apache.org/commons/#features
Comment 2 Sebb 2009-05-09 03:09:30 UTC
Thanks, did not know about that project.
I've just had a look at the XML Graphics Commons version and that also uses Error with rather cryptic messages, so that part has obviously not been addressed.