I've an class TCPDataLink implementing some TCP features using Socket. I also have an IOManager which does some logging when an error is thrown (on all my DataLink).
The problem is that I cannot find a way to catch exceptions of Socket event handlers from my IOManager Class. I do not want to inject Logger dependency inside my TCPDataLink class since I don't wan't to repeat the logging code in all my DataLink classes.
Example in a normal case :
// IOManager Class call in a normal case
try
{
tcpInstance.DoSomething
}
catch (MyCustomEx e)
{
// Log the problem
Logger.log(e.ToString());
}
In my problematic case :
// TCPDataLink.cs
...
socket.OnConnection += ConnectionHandler // Cannot try/catch or whatever
...
void ConnectionHandler(...)
{
// Code throwing Exceptions
}
According to this thread, external try/catch is not an option. So I've to catch Exception inside my ConnectionHanlder and... ?
What's my best alternative to log from my IOManager whitout the possibility to catch Exception ?
Thanks,