exception

Replacing Exceptions With Either/Maybe/Option

 ̄綄美尐妖づ 提交于 2020-01-12 03:52:50
问题 I came across this dead end while trying to replace exceptions with either monad in c#. Which leads me to think maybe it is not only language specific problem and more technique related missing feature. Let me try to re-explain it more globally: Given: I have a 3rd party function( a function that is imported into my code and I have no access to) which receives a lazy list (c# IEnumerable,f# Seq...) and consume it I Want: To apply a function (LINQ select,map...) on the method's lazy list

How can a unit test confirm an exception has been thrown

蓝咒 提交于 2020-01-12 03:16:53
问题 Im writing a unit test for a c# class, One of my tests should cause the method to throw an exception when the data is added. How can i use my unit test to confirm that the exception has been thrown? 回答1: It depends on what unit test framework you're using. In all cases you could do something like: [Test] public void MakeItGoBang() { Foo foo = new Foo(); try { foo.Bang(); Assert.Fail("Expected exception"); } catch (BangException) { // Expected } } In some frameworks there's an attribute you

ExpectedException Attribute Usage

青春壹個敷衍的年華 提交于 2020-01-12 03:06:48
问题 I am trying to work with the ExpectedException attribute in a C# UnitTest , but I am having issues getting it to work with my particular Exception . Here's what I got: NOTE: I wrapped asterisks around the line that is giving me the trouble. [ExpectedException(typeof(Exception))] public void TestSetCellContentsTwo() { // Create a new Spreadsheet instance for this test: SpreadSheet = new Spreadsheet(); // If name is null then an InvalidNameException should be thrown. Assert that the correct //

One Exception handler for all exceptions of a CLASS

妖精的绣舞 提交于 2020-01-11 22:24:31
问题 I have a class with number of methods and want to have one exception handler for them all. There are so many of these methods and they have different parameters, that it would be ugly to write try/catch for each of them. Do you maybe know a way where I can do it with having a one in class exception handler, which will handle them all. UPDATE: Many of you ask me why. The reason is that I am calling a data source with various methods. so my class has functions getData1, gedData2, getData3

One Exception handler for all exceptions of a CLASS

独自空忆成欢 提交于 2020-01-11 22:23:56
问题 I have a class with number of methods and want to have one exception handler for them all. There are so many of these methods and they have different parameters, that it would be ugly to write try/catch for each of them. Do you maybe know a way where I can do it with having a one in class exception handler, which will handle them all. UPDATE: Many of you ask me why. The reason is that I am calling a data source with various methods. so my class has functions getData1, gedData2, getData3

How to handle stale connections?

本小妞迷上赌 提交于 2020-01-11 17:06:13
问题 Ours is a J2EE app, using Struts-EJB-Hibernate on Websphere 6.1 over Mainframe/DB2 backend, that was recently moved to production. We are getting stale connection exception when the user login to the application first time or some times this exception occurs intermittently. on the second try the user able to log in to the application. The exact error message i am getting is empcom.ibm.websphere.ce.cm.StaleConnectionException: Execution failed due to a distribution protocol error that caused

How to handle stale connections?

人盡茶涼 提交于 2020-01-11 17:05:49
问题 Ours is a J2EE app, using Struts-EJB-Hibernate on Websphere 6.1 over Mainframe/DB2 backend, that was recently moved to production. We are getting stale connection exception when the user login to the application first time or some times this exception occurs intermittently. on the second try the user able to log in to the application. The exact error message i am getting is empcom.ibm.websphere.ce.cm.StaleConnectionException: Execution failed due to a distribution protocol error that caused

How to handle stale connections?

帅比萌擦擦* 提交于 2020-01-11 17:05:01
问题 Ours is a J2EE app, using Struts-EJB-Hibernate on Websphere 6.1 over Mainframe/DB2 backend, that was recently moved to production. We are getting stale connection exception when the user login to the application first time or some times this exception occurs intermittently. on the second try the user able to log in to the application. The exact error message i am getting is empcom.ibm.websphere.ce.cm.StaleConnectionException: Execution failed due to a distribution protocol error that caused

How can I rethrow an Inner Exception while maintaining the stack trace generated so far?

人走茶凉 提交于 2020-01-11 15:22:31
问题 Duplicate of: In C#, how can I rethrow InnerException without losing stack trace? I have some operations that I invoke asynchronously on a background thread. Sometimes, things go bad. When this happens, I tend to get a TargetInvocationException, which, while appropriate, is quite useless. What I really need is the TargetInvocationException's InnerException, like this: try { ReturnValue = myFunctionCall.Invoke(Target, Parameters); } catch (TargetInvocationException err) { throw err

How can I rethrow an Inner Exception while maintaining the stack trace generated so far?

偶尔善良 提交于 2020-01-11 15:22:03
问题 Duplicate of: In C#, how can I rethrow InnerException without losing stack trace? I have some operations that I invoke asynchronously on a background thread. Sometimes, things go bad. When this happens, I tend to get a TargetInvocationException, which, while appropriate, is quite useless. What I really need is the TargetInvocationException's InnerException, like this: try { ReturnValue = myFunctionCall.Invoke(Target, Parameters); } catch (TargetInvocationException err) { throw err