Guest User

Untitled

a guest
Aug 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. Can an exception be handled in another class, assembly, or abstract class?
  2. public class StackUserDataSource : AbstractEnhancedTableDataSource<StackUserDataServiceContext>
  3. {
  4. //.. stuff
  5.  
  6. public IEnumerable<StackUserDataModel> Select()
  7. {
  8. try
  9. {
  10. var results = from c in _ServiceContext.StackUserTable
  11. select c;
  12.  
  13. var query = results.AsTableServiceQuery();
  14. var queryResults = query.Execute();
  15.  
  16. return queryResults;
  17. }
  18. catch (StorageClientException e)
  19. {
  20.  
  21. // Todo: consider sticking this in another central location
  22. switch (e.ErrorCode)
  23. {
  24. case StorageErrorCode.AccessDenied:
  25. break;
  26. case StorageErrorCode.AccountNotFound:
  27. break;
  28. case StorageErrorCode.AuthenticationFailure:
  29. break;
  30. // ... Yadda yadda, handle some exceptions, not others.. this is a demo.
  31. case StorageErrorCode.TransportError:
  32. break;
  33. default:
  34. break;
  35. }
  36. throw;
  37. }
  38. }
  39.  
  40. try
  41. {
  42. var results = from c in _ServiceContext.StackUserTable
  43. select c;
  44.  
  45. var query = results.AsTableServiceQuery();
  46. var queryResults = query.Execute();
  47.  
  48. return queryResults;
  49. }
  50. catch (MyExternalExceptionHelperDLL e)
  51. {
  52. // all exceptions referenced in MyExternalHelper are passed below
  53. MyExternalExceptionHelper.ProcessException(e);
  54. }
  55. catch (exception)
  56. {
  57. }
  58.  
  59. try
  60. {
  61. var results = from c in _ServiceContext.StackUserTable
  62. select c;
  63.  
  64. var query = results.AsTableServiceQuery();
  65. var queryResults = query.Execute();
  66.  
  67. return queryResults;
  68. }
  69. catch (exception e)
  70. {
  71. MyExternalExceptionHelper.ProcessException(e);
  72.  
  73. // The problem is that I don't know how to catch exceptions thrown from that static method above,
  74. // or how to override that exception handling...
  75. }
  76.  
  77. public IEnumerable<StackUserDataModel> Select()
  78. {
  79. try
  80. {
  81. ...
  82. }
  83. catch (StorageClientException e)
  84. {
  85. // You could do this if there is no fancy processing to do
  86. if (!IsCatchableException(e))
  87. throw;
  88. }
  89. }
  90.  
  91. bool IsCatchableException(StorageClientException e)
  92. {
  93. ... optionally do some fancy processing of the exception, e.g. logging....
  94. switch (e.ErrorCode)
  95. {
  96. case StorageErrorCode.AccessDenied:
  97. case StorageErrorCode.AccountNotFound:
  98. ....
  99. return true;
  100. }
  101. }
Add Comment
Please, Sign In to add comment