One crucial thing at all times is to fight kyphosis and keep "military" posture (shoulders back and down, chest puffed out), and retract the scapula during exercises. Scapular retraction may be weak so strengthening that is crucial.
The big muscle that lifts the arm up and down is the deltoid, but there are also all these stabilizers that hold the humerous in place. The idea of a "ball and socket" joint is not accurate; really the humeral head just sort of rests against the gleno-humeral socket, and muscles and tendons hold it there, it isn't in any socket. If the stabilizers are too weak, the humeral head is not held in the right place, which can cause pinches and tears and general badness. These stabilizers need to be strengthened to do anything - throw a ball, non-shoulder exercises, etc.
The shoulder is very mobile, but a lot of the angles it can be in are actually very hard on the joint. If your stabilizers or tissues are too weak, you should not put it in difficult positions under load. The safe range of motion is with your arm at 20-50 degrees in front of your body, and from down at your side up to parallel with your shoulders. That means not raising your elbow above your shoulders and not putting your elbow parallel to the plane of your body or behind. You should stretch your range of motion without load, but don't go into those positions under load.
In particular, that means some of the standard weight lifting moves are forbidden. Standard barbell bench presses are very bad. The safest substitute is the dumbell incline bench press with the hands in "neutral" position (turned at a 45 degree angle so your palms face your crotch). Another big standard press that's forbidden is the back squat, because of how you hold the bar behind your back. Possibile substitutes are the front squat, hack squat, or the sled squat machines.
Upright rows are very bad for the shoulder and should never ever be done even when the shoulder is fully healthy. The same goes for military presses behind the head or lat pulldowns behind the head. There's no reason to do these, don't do them.
Throwing a ball is something I continue to do which is very dangerous for shoulder health. It's really crucial to warm up and stretch before throwing as it's a very hard motion on the shoulder. The crucial thing with throwing is to think of it a full body "jerk" motion like an olympic lift with a big weight. To throw properly you need to generate the force from your legs and hips. All your shoulder strength should be focused on stabilizing the shoulder joint as your trunk power jerks your body and whips your arm to release the ball. The way you can easily get injured is if you stand still and try to launch the ball just by jerking your shoulder.
To work the stabilizers, you probably only need zero weight or a tiny bit of weight. Most physical therapists would recommend rubber bands. You need to strengthen scapular retraction and protraction. If you use computers you are probably in a state of constant weak protraction and your retractors are atrophied.
Most of the stabilizers can be hit with humeral rotations. Imagine your arm rotating around the humerous. All you do is bend your elbow 90 degrees in some comfortable position (eg. at your side, or straight out from your shoulder, lying on your side, lying on your stomach), then rotate your arm around the axis of the humerous in each direction with as much resistance as needed. This can be done as a high-rep low-weight move.
The other simple lift is a lateral raise. This actually is just a deltoid move but it's a safe direct way to target it. The arm should move in the safe plane, that's 20-30 degrees in from of the body, with elbow straight and thumb pointing up. Don't raise the elbow above the shoulder. Next time you see someone at the gym doing lateral raises with their arms straight out at their sides and raising their elbows way above the shoulder, have a good laugh.
The trickiest thing is that you need to work these stabilizers, but working them makes them fatigued, and when they are fatigued it's dangerous to do any other exercise that uses the shoulder. When you're not specifically working the stabilizers, you need to hold the shoulders in a strict position of scapular retraction, back and down. If your shoulders are too tired or weak to keep this posture when you do your other exercises - don't do them.