Where does the Scripture say that you need to be in the state of Divine Grace in order to go to Heaven? If I am correct, the Catholic Church teaches that you need to be in the state of Divine Grace at the moment of your death if you wish to go to Heaven. 

If you are not, then you are automatically cursed for all Eternity and go straight to Hell.

Let's say a man had devoted his whole life to God, believed in Jesus and lived his life according to what Jesus had said, but prior to his death committed some kind of 'eternal' sin. Still, he didn't stop to believe in Jesus for even a second. Let's say he was caught off guard by temptation and died shortly afterwards.

According to the idea of Divine Grace, he goes to Hell.

My two questions:

1) How can this be just whatsoever ? 

2) Where in the Scripture does Jesus say that you will end up in Hell if you are not in Divine Grace state ? If I am correct he doesn't say it at all and the whole concept has been invented by the later Tradition of the Catholic Church, not by Jesus himself.

I'm not trying to offend anyone by asking these questions. I believe in God, Christ and the Scripture. I also have a deep faith that the Church tries to bring us to God as close possible. I'm just trying to figure out the purpose of some of the 'constructs' like Divine Grace and whether they can have such a big impact on our salvation.
If I am correct, the Catholic Church teaches that you need to be in the state of Divine Grace at the moment of your death if you wish to go to Heaven.


Not only the Catholic Church, but the Bible itself teaches that you must be in a state of grace or status gratiae at the moment of your death if you wish to go to Heaven.

In Rom. 5:1-2, the apostle Paul wrote,


  Therefore, being justified by faith, we have peace with God by our Lord Jesus Christ, by whom we also have access by faith into this grace wherein we stand, and rejoice in hope of the glory of God.


The Greek εἰς τὴν χάριν ταύτην ἐν ᾗ ἑστήκαμε, meaning "into this grace wherein we stand," is the basis for the idea of a "state of grace" or Latin status gratiae.1 If you are not in a state of grace, that is, if you do not stand in grace, then you are not saved; you are not justified by faith.


  If you are not, then you are automatically cursed for all Eternity and go straight to Hell.


Actually, this is true. If you do not stand in grace, you will suffer eternal torment in Gehenna ("Hell"). The logical corollary of Rom. 5:2 is that if you do not stand in grace, then you do not have faith in the Lord Jesus Christ, for it is "by faith" (τῇ πίστει) that one may have "access" (προσαγωγή) to stand in grace. Ergo, if you do not have faith in order to have access to stand in grace, then neither do you have peace with God, nor are you justified by faith (cp. Rom. 5:1).

If you have faith,


you are justified
you have peace with God
you have access to stand in grace


If you do not stand in grace,


you do not have peace with God
you are not justified
you do not have faith


The consequence of the latter is eternal torment in Gehenna.

All this being said, I think you should also know that one may stand in grace (i.e., a state of grace) yet be a sinner. However, if we sin, we must confess and repent of our sins, and "he is faithful and just to forgive us our sins, and to cleanse us from all unrighteousness" (1 John 1:9). Sin defiles (Mark 7:23), thus the corollary is that if we do not confess and repent of our sins, we are defiled with unrighteousness, but "nothing that defiles shall enter into it" (Rev. 21:27), that is, God's kingdom and New Jerusalem. For those standing in grace who sin without confessing and repenting their sin(s) before death, they must still be purified from the unrighteousness of their sins after death by enduring Purgatory (purification).

The Catechism of the Catholic Church, §1030, states,


  All who die in God's grace and friendship, but still imperfectly purified, are indeed assured of their eternal salvation; but after death they undergo purification, so as to achieve the holiness necessary to enter the joy of heaven.




Footnotes

The Latin is in gratiam istam in qua stamus. The word stamus is a verb conjugated from the lemma sto. The word status is a noun related to the verb sto; it means "place; position; state; status."