Dynamically encircling an exceptional point in non-Hermitian systems has drawn great attention recently, since a nonadiabatic transition process can occur and lead to intriguing phenomena and applications such as the asymmetric switching of modes. While all previous experiments have been restricted to two-state systems, the dynamics in multistate systems where more complex topology can be formed by exceptional points, is still unknown and associated experiments remain elusive. Here, we propose an on-chip photonic system in which an arbitrary number of exceptional points can be encircled dynamically. We reveal in experiment a robust state-switching rule for multistate systems, and extend it to an infinite-period system in which an exceptional line is encircled with outcomes being located at the Brillouin-zone boundary. The proposed versatile platform is expected to reveal more physics related to multiple exceptional points and exceptional lines, and give rise to applications in multistate non-Hermitian systems.