Yes, but it involves contacting your nearest consulate/embassy before boarding the plane. They normally verify some stuff internally (which is why it helps immensely to have photocopies that speed up the process as that contains the relevant numbers/barcodes that allow them to look you up quickly) and then they give you an "emergency travel document" or a new passport, depending on the situation. The ETD lets you travel back to your home country and then handle things from there.