In Catholic tradition, the story of Joseph's death is known as the Happy Death of Saint Joseph. According to this story, Joseph entered an ecstatic trance one day before he died and glimpsed the divine. He understood everything that he believed and saw all of those things he only knew by faith while alive. The story also mentions a long period of sickness and suffering before he died.
The story of Joseph's death, as accepted by Catholic tradition, was written in the "Mystical City of God," a book written in the 17th century detailing the life of the Virgin Mary.
Very little is known about Joseph's death from a historical perspective, but it is thought that he died of natural causes some time after Jesus visited the temple at 12, but before he was baptized at 30. John 19:26-27 implies that Joseph was already dead at the time of Jesus' crucifixion. He is thought to have been born around 100 BCE, and his death occurred around 1 AD.
Other sources muddling the information are the apocryphal writings. The "Protevangelium of James," written in the second century, and the "History of Joseph the Carpenter," written in the fourth century, present Joseph as a much older widower who already had children when he married the Virgin Mary. These writings are not widely accepted as historical fact, however.