(a) The divisions of the juvenile court department shall continue to have jurisdiction over children who attain their eighteenth birthday pending final adjudication of their cases, including all remands and retrials following appeals from their cases, or during continuances or probation, or after their cases have been placed on file, or for any other proceeding arising out of their cases. Except as provided in subsection (b), nothing herein shall authorize the commitment of a person to the department of youth services after he has attained his twentieth birthday. If a child commits an offense prior to his eighteenth birthday, and is not apprehended until between such child's eighteenth and nineteenth birthday, the court shall deal with such child in the same manner as if he has not attained his eighteenth birthday, and all provisions and rights applicable to a child under 18 shall apply to such child.