تخطَّ إلى المحتوى

Generic Exception Thrown (ARCH4167)

هذا المحتوى غير متوفر بلغتك بعد.

Key java.logging.throw-generic-exception · Severity warning · Category logging

Throwing a generic type such as Exception or RuntimeException forces callers into broad catch blocks and makes it impossible to distinguish different error conditions. Define specific, domain-relevant exceptions.

public Order load(String id) {
if (id == null) {
throw new RuntimeException("id must not be null");
}
return repository.find(id);
}
public Order load(String id) {
if (id == null) {
throw new IllegalArgumentException("id must not be null");
}
return repository.find(id);
}

Throw a specific or domain-specific exception type that describes the condition instead of the base/generic type.