You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The GTFS exceptions in namespace GTFS.Exceptions all derive from the System.Exception class.
In order to log all issues that occur while reading a GTFS feed, one now needs to either catch the base class System.Exception or catch all exceptions from namespace GTFS.Exceptions explicitly.
Catching System.Exception is considered bad practice. The second approach is also not ideal because if a new GTFS exception is added, it will pass through.
IMHO, it is best to add an abstract base class (e.g. class GTFSExceptionBase) for all GTFS exceptions in namespace GTFS.Exceptions.
Ugly workaround for now:
try
{
gtfsData.GtfsFeed = reader.Read(gtfsDirectorySource);
}
catch (Exception ex)
{
var type = ex.GetType();
if (!type.FullName.StartsWith("GTFS.Exceptions"))
{
throw;
}
// TODO: add logging here
}
The text was updated successfully, but these errors were encountered:
Added class GTFSExceptionBase, derived all exceptions currently in namespace GTFS.Exceptions from it and added unit test to ensure all exceptions derive from this base.
rorlic
pushed a commit
to rorlic/GTFS
that referenced
this issue
Feb 10, 2016
The GTFS exceptions in
namespace GTFS.Exceptions
all derive from theSystem.Exception
class.In order to log all issues that occur while reading a GTFS feed, one now needs to either catch the base
class System.Exception
or catch all exceptions fromnamespace GTFS.Exceptions
explicitly.Catching
System.Exception
is considered bad practice. The second approach is also not ideal because if a new GTFS exception is added, it will pass through.IMHO, it is best to add an abstract base class (e.g.
class GTFSExceptionBase
) for all GTFS exceptions innamespace GTFS.Exceptions
.Ugly workaround for now:
The text was updated successfully, but these errors were encountered: