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
Copy file name to clipboardExpand all lines: rules/S8126/apex/rule.adoc
+3-7Lines changed: 3 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
-
This rule raises an issue when a custom exception class does not end with the suffix "Exception" or does not properly extend the Exception class.
1
+
This rule raises an issue when a custom exception class does not end with the suffix "Exception" or a class name including "Error" does not extend the Exception class.
2
2
3
3
== Why is this an issue?
4
4
5
5
Custom exception classes serve as a way to handle specific error conditions in your Apex code. When these classes don't follow proper naming conventions, it creates several problems.
6
6
7
-
First, unclear naming makes code harder to understand and maintain. A class named `MyError` or `CustomHandler` doesn't immediately signal to other developers that it's an exception class. This lack of clarity can lead to confusion when reading or debugging code.
7
+
First, unclear naming makes code harder to understand and maintain. A class named ``++MyError++`` doesn't immediately signal to other developers that it's an exception class. This lack of clarity can lead to confusion when reading or debugging code.
8
8
9
9
Second, Apex follows Java conventions where exception classes should end with "Exception". This convention is widely recognized and expected by developers. Breaking this convention makes your code inconsistent with established patterns.
10
10
@@ -34,18 +34,14 @@ Rename your custom exception class to end with 'Exception' and ensure it properl
34
34
----
35
35
public class MyError extends Exception {} // Noncompliant
36
36
37
-
public class CustomHandler extends Exception {} // Noncompliant
38
-
39
37
public class ValidationIssue extends Exception {} // Noncompliant
40
38
----
41
39
42
40
==== Compliant solution
43
41
44
42
[source,apex,diff-id=1,diff-type=compliant]
45
43
----
46
-
public class MyCustomException extends Exception {}
47
-
48
-
public class CustomProcessException extends Exception {}
44
+
public class MyErrorException extends Exception {}
49
45
50
46
public class ValidationException extends Exception {}
0 commit comments