throw

Can you throw within a conditional expression? (was: How can bounds-checking be extended to multiple dimensions?)

浪子不回头ぞ 提交于 2020-01-01 18:12:37
问题 Note: I solved the original problem by realizing a completely different one. See the addendum for the new actual problem, but you can read the previous part for context. This is an extension of one of my previous posts. I made a container class based on that answer: template < typename T, unsigned N0, unsigned ...N > struct array_md { // There's a class template specialization with no extents. // Imagine the various N... components are bracket-enclosed instead // of comma-separated. And if "N

C++: If an exception is thrown, are objects that go out of scope destroyed?

空扰寡人 提交于 2019-12-30 21:21:53
问题 Normally it would be destructed upon the scope ending.. I could see issues occurring if exceptions were thrown though. 回答1: Yes. C++ Standard n3337 15 Exception handling § 15.2 Constructors and destructors 1) As control passes from a throw-expression to a handler, destructors are invoked for all automatic objects constructed since the try block was entered . The automatic objects are destroyed in the reverse order of the completion of their construction. 2) An object of any storage duration

C# Real Time Try Catch

早过忘川 提交于 2019-12-30 06:29:10
问题 I'd like a response from someone who actually does real-time programming in C# or who really understands the language internals. I know that exceptions should not be used to handle normal processing, but only to detect error conditions. There is plenty of discussion on that topic. I'd like to know if there is any run time slow-down from simply having a try/catch block in place (which never catches an exception unless the program will have to end anyway). The try/catch block is inside a

difference between throw and throw ex in c# .net [duplicate]

一世执手 提交于 2019-12-30 04:30:14
问题 This question already has answers here : Is there a difference between “throw” and “throw ex”? (10 answers) Closed 5 years ago . Can anyone tell me difference between throw and throw ex in brief? I read that throw stores previous exceptions, not getting this line. Can i get this in brief with example? 回答1: Yes - throw re-throws the exception that was caught, and preserves the stack trace. throw ex throws the same exception, but resets the stack trace to that method. Unless you want to reset

Java abstract classes which throw

随声附和 提交于 2019-12-29 09:04:33
问题 If I have an abstract class with the following function - abstract class A{ void foo(String s) throws Exception{ throw new Exception("exception!"); } } And then another class that extends the abstract class and implements its own version of foo - class B extends A{ void foo(String s){ //do stuff that does *not* throw an exception } } Will this create problems? Specifically in the following test case - Collection<A> col = new Collection<A>(); B b = new B(); col.add(b); for(A a : col){ a.foo();

Java abstract classes which throw

 ̄綄美尐妖づ 提交于 2019-12-29 09:04:01
问题 If I have an abstract class with the following function - abstract class A{ void foo(String s) throws Exception{ throw new Exception("exception!"); } } And then another class that extends the abstract class and implements its own version of foo - class B extends A{ void foo(String s){ //do stuff that does *not* throw an exception } } Will this create problems? Specifically in the following test case - Collection<A> col = new Collection<A>(); B b = new B(); col.add(b); for(A a : col){ a.foo();

What is the point of `void func() throw(type)`?

那年仲夏 提交于 2019-12-29 07:15:09
问题 I know this is a valid c++ program. What is the point of the throw in the function declarement? AFAIK it does nothing and isnt used for anything. #include <exception> void func() throw(std::exception) { } int main() { return 0; } 回答1: That is an exception specification, and it is almost certainly a bad idea. It states that func may throw a std::exception , and any other exception that func emits will result in a call to unexpected(). 回答2: It specifies that any std::exception can be thrown

C++: Throwing a derived class by reference does not work when catching base class

痞子三分冷 提交于 2019-12-29 06:46:06
问题 I want to throw my own exceptions with the base class Exception . There is a virtual method print which will be overwritten by the subclasses. I only catch the type Exception& and use print to get the specific error. The problem is that once I throw a reference of a subclass it is trated as if it were the base class. Here is an example: #include <iostream> using namespace std; class Exception { public: virtual void print() { cout << "Exception" << endl; } }; class IllegalArgumentException :

Throw keyword in Java [closed]

泪湿孤枕 提交于 2019-12-25 19:07:42
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 6 years ago . In Java, is the keyword (throw) only used for throwing exception that you've created. If not, can someone give an example of how it is used outside of your own made exceptions. 回答1: You can throw anything that extends Throwable void greet(String name) { if (name == null) { throw new

Java. Why can i pass an object argument, if in the method definition the arguments are the type of an interface?

北城以北 提交于 2019-12-25 01:14:03
问题 Let's say I have the following interface: public interface Numeric { public Numeric addition(Numeric x,Numeric y); } And the following class: public class Complex implements Numeric { private int real; private int img; public Complex(int real, int img){ this.real = real; this.img = img; } public Numeric addition(Numeric x, Numeric y){ if (x instanceof Complex && y instanceof Complex){ Complex n1 = (Complex)x; Complex n2 = (Complex)y; return new Complex(n1.getReal() + n1.getReal(), n2.getImg()