Re: redesign exception
Error codes is the way to go.
Knock yourself out:
I don't know what it means cause I am not a native English speaker :)
I want to add a new way of catch exception in the java language:
catch (Fault fault, someExceptionCodes)
someExceptionCodes will be varargs.
so no "switch( error.getCode() )" is required.
I actually imitated the syntax with lambda in java 8. Here is the blog and=
code:
http://tri-katch.blogspot.ca
The github project is: https://github.com/pahakia/lib.
Java 8 example: https://github.com/pahakia/lambda.
https://github.com/pahakia/lambda/tree/master/fault-test/src/test/java/paha=
kia/fault/lambda.
taken from the blog:
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