A castle doctrine (also known as a castle law or a defense of habitation law) is a legal doctrine that designates a person's abode as a place in which that person has certain protections and immunities permitting him or her, in certain circumstances, to use force (up to and including deadly force) to defend themselves against an intruder. If someone breaks into your home while you are there, assume they are there to do harm to you. A hotel or motel room you rent may be covered under the castle doctrine, too. This is a very general description, and since the details of each state's doctrine varies, be sure to get the details that pertain to where you live or travel frequently BEFORE you face an invasion.
Castle Doctrine laws most often instruct the courts that they must assume that anyone who breaks into your house while you are inside is there to cause you harm. But you still need to protect yourself legally as well as physically. The best way to do that is to establish that you are a reluctant participant in the deadly force encounter. Don’t go searching for the bad guy. Your problems don’t end when you shoot the intruder - they begin - so try to end the situation without using deadly force if you can.
The United States Concealed Carry Association advises that your best bet is to try and call 911 first. Basically grab the phone and your firearm at the same time. If you can, before anything happens, give your location to the 911 operator. Then drop the phone and let the 911 operators hear you giving the warnings to the bad guys before you ever fire. Yelling "I'm armed! And I've called the police" is a definite way to bolster your position legally because it shows both your reluctance to shoot, and your having given the intruder his "last chance" to depart before you use force. Then essentially the prosecutor has to challenge your defense and prove that you voluntarily chose to fire and weren’t reacting to the situation.
Not only will yelling that you're armed help in court, if needed, it could save a life. Not just the life of the "bad guy" but perhaps that of a drunk neighbor, a family member, or your daughter's boyfriend sneaking in or out. If the intruder IS a teenager or someone else who means no harm, they will likely run out or yell out not to shoot and give their name. If they DO turn out to be something more sinister, even a thug doesn't want to get shot, and your announcement may take them by surprise. They weren't expecting you to have a gun, so they may flee immediately. If the burglar heeds your warning and departs, let he/she/them do so and then let the police attempt to find them. Think about this scenario NOW, before you are placed in danger in the middle of the night.
Always remember that in any deadly force encounter, even when it involves invasion of your home, deadly force can be used only as a means of last resort, when all lesser means have failed or cannot be reasonably employed. The situation surrounding the use of deadly force doesn't change the condition. Unfortunately, in our litigious society, even the dead can sue you, so clearly establish that you were left with no other option. You never want to kill anyone, BUT you also never want to be a victim!
As always, this is not legal advice. Read and understand the laws of your state.