exception

FaultException and custom exception WCF

≡放荡痞女 提交于 2019-12-29 07:55:11
问题 I have a question on how to send a custom exception as FaultException. It works when I use a system Exception like ArgumentException, but if I change it to my custom exception "TestException" it fails. I can’t get the configuration for the service reference, when I try to add it. Works: [OperationContract] [FaultContract(typeof(ArgumentException))] [TransportChannel TestMethod (); public Void TestMethod() { throw new FaultException<ArgumentException>(new ArgumentException("test"), new

Exception TypeError warning sometimes shown, sometimes not when using throw method of generator

扶醉桌前 提交于 2019-12-29 07:39:13
问题 There is this code: class MyException(Exception): pass def gen(): for i in range(3): try: yield i except MyException: print("MyException!") a = gen() next(a) a.throw(MyException) Running this code: $ python3.3 main.py MyException! $ python3.3 main.py MyException! Exception TypeError: TypeError('catching classes that do not inherit from BaseException is not allowed',) in <generator object gen at 0xb712efa4> ignored $ python3.3 main.py MyException! $ python3.3 main.py MyException! $ python3.3

Checking if a file is in use without try catch?

梦想与她 提交于 2019-12-29 07:31:51
问题 Is there a way I can check if a file is in use or is not opened by other process without just trying to open it and catching an exception? Is there no service method to test such a thing? 回答1: Even if there was, it wouldn't do you much good since you would still have to catch the exception in order to handle the race condition where the file became unavailable in between your initial check and your actual attempt to open/access it. I can't think of any compelling advantage to a preliminary

Is there a good method in C# for throwing an exception on a given thread

我的梦境 提交于 2019-12-29 05:23:46
问题 The code that I want to write is like this: void MethodOnThreadA() { for (;;) { // Do stuff if (ErrorConditionMet) ThrowOnThread(threadB, new MyException(...)); } } void MethodOnThreadB() { try { for (;;) { // Do stuff } } catch (MyException ex) { // Do the right thing for this exception. } } I know I can have thread B periodically check, in thread safe way, to see if a flag has been set by thread A, but that makes the code more complicated. Is there a better mechanism that I can use? Here is

Is there a good method in C# for throwing an exception on a given thread

人走茶凉 提交于 2019-12-29 05:22:14
问题 The code that I want to write is like this: void MethodOnThreadA() { for (;;) { // Do stuff if (ErrorConditionMet) ThrowOnThread(threadB, new MyException(...)); } } void MethodOnThreadB() { try { for (;;) { // Do stuff } } catch (MyException ex) { // Do the right thing for this exception. } } I know I can have thread B periodically check, in thread safe way, to see if a flag has been set by thread A, but that makes the code more complicated. Is there a better mechanism that I can use? Here is

Why is C++0x's `noexcept` checked dynamically?

无人久伴 提交于 2019-12-29 04:29:11
问题 I am curious about the rationale behind noexcept in the C++0x FCD. throw(X) was deprecated, but noexcept seems to do the same thing. Is there a reason that noexcept isn't checked at compile time? It seems that it would be better if these functions were checked statically that they only called throwing functions within a try block. 回答1: If I remember throw has been deprecated because there is no way to specify all the exceptions a template function can throw. Even for non-template functions

UnexpectedRollbackException - a full scenario analysis

时光总嘲笑我的痴心妄想 提交于 2019-12-29 03:54:57
问题 All I know about this exception is from Spring's documentation and some forum posts with frostrated developers pasting huge stack traces, and no replies. From Spring's documentation: Thrown when an attempt to commit a transaction resulted in an unexpected rollback I want to understand once and for all Exactly what causes it? Where did the rollback occur? in the App Server code or in the Database? Was it caused due to a specific underlying exception (e.g. something from java.sql.*)? Is it

How to create exceptions?

泪湿孤枕 提交于 2019-12-29 03:39:06
问题 So I have an upcoming assignment dealing with exceptions and using them in my current address book program that most of the homework is centered around. I decided to play around with exceptions and the whole try catch thing, and using a class design, which is what I will eventually have to do for my assignment in a couple of weeks. I have working code that check the exception just fine, but what I want to know, is if there is a way to standardize my error message function, (i.e my what() call

Java Exception Naming Conventions

五迷三道 提交于 2019-12-29 03:36:06
问题 In Java, is there a semantic difference between using " Illegal " (as in IllegalArgumentException ) versus " Invalid " (as in javax.activity.InvalidActivityException )? During the course of an assignment it became useful to write a subclass of IllegalArgumentException to represent a series of input characters that cannot be tokenized, and I'm wondering whether convention says to use InvalidTokenException or IllegalTokenException . The only difference I can find so far is that java.lang seems

Java ImageIO IIOException: Unsupported image type?

自闭症网瘾萝莉.ら 提交于 2019-12-29 03:35:05
问题 Working with images in Java for the first time and am getting some bizarro exceptions that aren't documented very well. Here's the line of code that is failing: BufferedImage imgSelected = ImageIO.read(new File("/abs/url/to/file/image.jpg")); This line is throwing an IIOException with Unsupported image type as the exception message. I have checked and re-checked that it is in fact this line throwing the exception, that the File object is valid, that the URL is valid, and that the image.jpg is