You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code in the Modern modules of BoneJ should throw exceptions in a consistent manner.
Exceptions related to user-input, I/O and other areas where exceptions are to be expected, should be caught with a catch block. The user should be informed of the error, and the stack trace logged with a call to LogService.trace(). This way the exception info can be viewed by selecting Edit > Options > ImageJ2... and setting SciJava log level to TRACE if need be. Normally the user shouldn't see these kinds of exceptions. See issue #82.
NullPointer, IllegalArgument and other exceptions that result from programmer errors should not be caught. Otherwise these bugs might go unnoticed. These exceptions should only be thrown if they otherwise wouldn't already happen in the scope, or when they add new information about valid behaviour or data. Some examples:
// Example 1publicstaticcharinitial(finalStringname) {
// Throwing a NullPointerException would be redundant,// because the next line will throw it if name == null returnname.charAt(0);
}
// Example 2publicclassEmployee {
privateStringname;
publicStringgetName() { returnname; }
publicvoidsetName(finalStringname) throwsNullPointerException {
// Exception is thrown, because otherwise there's no telling when the null name field// would cause troubleif (name == null)
thrownewNullPointerException("Name cannot be null!");
this.name = name;
}
}
// Example 3publicvoidsetRadius(finaldoubler) {
// Exception thrown, because it adds a new constraint for valid dataif (r <= 0)
thrownewIllegalArgumentException("Radius must be positive!");
radius = r;
}
// Example 4publicenumDay {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
THURSDAY, FRIDAY, SATURDAY
}
publicStringdayName(finalDaycurrentDay) {
switch(currentDay) {
caseSUNDAY:
return"Sunday";
...
caseMONDAY:
return"Monday";
default:
// Exception thrown, because code has entered a bad paththrownewRuntimeException("Somebody forgot to cover all valid cases!");
}
}
Code that migrates from BoneJ to the framework should follow the exception conventions presented there.
The text was updated successfully, but these errors were encountered:
The code in the
Modern
modules of BoneJ should throw exceptions in a consistent manner.Exceptions related to user-input, I/O and other areas where exceptions are to be expected, should be caught with a
catch
block. The user should be informed of the error, and the stack trace logged with a call toLogService.trace()
. This way the exception info can be viewed by selecting Edit > Options > ImageJ2... and setting SciJava log level to TRACE if need be. Normally the user shouldn't see these kinds of exceptions. See issue #82.NullPointer
,IllegalArgument
and other exceptions that result from programmer errors should not be caught. Otherwise these bugs might go unnoticed. These exceptions should only be thrown if they otherwise wouldn't already happen in the scope, or when they add new information about valid behaviour or data. Some examples:Code that migrates from BoneJ to the framework should follow the exception conventions presented there.
The text was updated successfully, but these errors were encountered: