In C #, doing the following will destroy the trace of the exception stack:
try{
throw new RuntimeException();
}
catch(Exception e){
throw e;
}
Because of this, it is preferable to use throw, rather than throw e. This will allow you to propagate the same exception up, instead of wrapping it in a new one.
However, using throw;without specifying an exception object is invalid syntax in PHP. Does this problem simply not exist in PHP? Will I use throw $ e as follows so as not to destroy the stack trace?
<?php
try{
throw new RuntimeException();
}
catch(Exception $e){
throw $e;
}
source
share