I don't know about the Twain connection, but I believe that Blaise Pascal first made this "apology."