Things could have been a whole lot worse at 42 Walnut Park in Roxbury yesterday morning.

For starters, Dondre Crawford, 20, could easily have killed the 19-year-old kid he allegedly opened fire on as the pair walked down the street, right past a cop working a detail.

But he didn’t.

When Crawford was chased and confronted by the detail cop who witnessed the shooting, he tried to do something even more profoundly stupid. He allegedly tried to shoot the cop, but realizing there were no bullets left in the gun, he threw it at the officer instead, hitting him in the chest and then breaking into a run.

Dondre Crawford was soon spotted and apprehended by another Boston cop, who was also working a paid detail in the area. By that time, a state police helicopter had started circling the neighborhood.

The cops recovered a .22 caliber semi-automatic pistol along with five spent shell casings. Dondre Crawford, who had been identified by both police officers, had his hands swabbed for gun residue.

The police work that resulted in the capture of an active shooting suspect and the recovery of the weapon was nothing short of heroic. Still, the incident at 42 Walnut Park will most likely disappear in the yearly crime stats because this was a point-blank shooting that miraculously did not leave a body on the street.

The victim — who is 19 and, like Crawford, no stranger to police — chose to drive himself to Boston Medical Center after the gunplay. He was described as having suffered non-life-threatening injuries to both legs. Like most streetwise victims who cheat death, this kid was not, shall we say, forthcoming with the cops who followed him to the hospital.

But whether he decides to press charges is largely beside the point, since the primary witnesses to this shooting at Walnut Park happen to be the pair of Boston police officers who apprehended Dondre Crawford. And they will be in court today.

The kid with the wounds in his legs should probably thank the cops for increasing his life expectancy. Attempted assault on a police officer with a firearm should take Dondre Crawford out of circulation for at least a few years.

Whether that buys this lucky 19-year-old kid any peace of mind, to say nothing of security, remains to be seen.

A potential murder in Walnut Park was avoided yesterday. Five shots were fired, but the targeted victim was able to get himself to the hospital. The guy who shot him was captured, but who can say what the future holds for this 19-year-old man who cheated death at Walnut Park.