Fix deprecated dequeue function

Legacy code depends on this function returning END_OF_STREAM instead of
throwing an exception. Thus, we need to catch the exception and convert
it to an END_OF_STREAM to make this function meaningful. (I ran into
this problem using some legacy code).