nus-cs2113-AY2223S2 / forum

10 stars 0 forks source link

Public Class Exception vs Public Static Nested Class Exception #27

Open JangusRoundstone opened 1 year ago

JangusRoundstone commented 1 year ago
Screen Shot 2023-02-08 at 11 39 49 PM

In the 3rd key exercise in week 5, IllegalShapeException given is defined without the static keyword. From what I found the convention is indeed to define exception as a public class, and not as a static nested class inside the main class.

May I know why that is the case? Are there uses to exceptions defined as static nested class inside main? Based on my understanding, static nested exception class could potentially be useful for defining very specific exception that is exclusive to current main class you are running.

Any thoughts are welcomed!

Magmanat commented 1 year ago

I think its just to ensure the main class you are running is cleaner.

Could always break up your exceptions into several different exception packages to further classify them and would be much easier to reference