For example, suppose Alice stabs Bob and then runs away, and a police officer happens upon Bob as he lies in the gutter, bleeding to death. If Bob manages to sputter out with his last words, "I'm dying - Alice stabbed me" (or even just "Alice did it"), the officer can testify to that in court.
The declarant does not actually have to die for the statement to be admissible, but they need to have had a genuine belief that they were going to die, and they must be unavailable to testify in court. In the above scenario, if Bob were to recover instead of dying, and were able to testify in court, the officer would no longer be able to testify to the statement. It would then constitute hearsay, and not fall into the exception. Furthermore, the statement must relate to the circumstances or the cause of the declarant's own death. If Bob's last words are "Alice killed Carol", that statement will not fall within the exception, and will be inadmissible (unless Alice killed Bob and Carol in the same act).
Furthermore, as with all testimony, the dying declaration will be inadmissible unless it is based on the declarant's actual knowledge. Suppose, for example, Bob bought a cup of coffee at the airport, and was stricken with food poisoning. If his dying last words were that "the people who sold them the coffee mix must have used a defective packing machine", that statement would be inadmissible despite the hearsay exception because Bob had no way of knowing anything about the conditions in which the coffee was packed.
In U.S. federal courts, the dying declaration exception is limited to civil cases. It cannot be used in any kind of criminal proceeding because defendants have the right to confront witnesses against them. This rule is applicable even when the defendant is responsible for the witness's absence. Although many U.S. States copy the Federal Rules of Evidence in their statutes, some permit the admission of dying declarations in all cases.
The first use of the dying declaration exception in American law was in the 1770 murder trial of the British soldiers responsible for the Boston Massacre. One of the victims, Patrick Carr, told his doctor before he died that the soldiers had been provoked. The doctor's testimony helped defense attorney John Adams to secure acquittals for some of the defendants and reduced charges for the rest.
If the defendant is convicted of homicide, but the reliability of the 'dying declaration' is in question, there is grounds for an appeal.