in an application I made that uses AWT standard classes, a call to Color constructor throws the following Exception message:
run:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Color parameter outside of expected range: Red
at java.awt.Color.testColorValueRange(Color.java:310)
at java.awt.Color.<init>(Color.java:395)
at java.awt.Color.<init>(Color.java:369)
at mandelbrotset.DrawingArea.translateColor(DrawingArea.java:106)
at mandelbrotset.DrawingArea.drawMandelbrotSet(DrawingArea.java:75)
at mandelbrotset.DrawingArea.paintComponent(DrawingArea.java:45)
at javax.swing.JComponent.paint(JComponent.java:1054)
is there any way to change this message (including in this case the value of red component)?
I thought of defining a new class NewColor that extends Color and throws the modified exception in the constructor, but the new class constructor must start with a call to super(red, green, blu) and so the standard testColorValueRange(int r, int g, int b, int a) is called and the standard exception is thrown.
Thanks for any help.
Catch the unwanted exception and throw the desired exception.
Something like this:
You can create a new exception class (DesiredException in the example above) that takes the existing exception and “changes” the values to what you want.
It is also possible that (in the code above) UnwantedExceptionType and DesiredException are the same type, you just set the desired values in DesiredException.