exception

Best Practice Return Value vs Exception vs Enum [closed]

主宰稳场 提交于 2020-01-01 04:18:10
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . I am trying to find out the advantages and disadvantages for a method with multiple result values. For example I'm using a login-method. If the login was successful, it will pass, otherwise I need to know why it failed. 1. Return true or false (Not enough information) bool

Rethrowing exceptions

谁说我不能喝 提交于 2020-01-01 04:14:43
问题 Why doesn't the following doesn't handle the exception that was rethrown? I tried all the combinations but none of them would show the output in last catch so I'm confused! Derived D; try { throw D; } catch ( const Derived &d) { throw; } catch (const Base &b) { cout << "caught!" << endl; } Derived D; try { throw D; } catch ( const Derived d) { throw; } catch (const Base b) { cout << "caught!" << endl; } Derived D; try { throw D; } catch ( const Derived d) { throw; } catch (const Base &b) {

Preserving original StackTrace/LineNumbers in .NET Exceptions

浪子不回头ぞ 提交于 2020-01-01 04:09:12
问题 Understanding the difference between throw ex and throw , why is the original StackTrace preserved in this example: static void Main(string[] args) { try { LongFaultyMethod(); } catch (System.Exception ex) { Console.WriteLine(ex.StackTrace); } } static void LongFaultyMethod() { try { int x = 20; SomethingThatThrowsException(x); } catch (Exception) { throw; } } static void SomethingThatThrowsException(int x) { int y = x / (x - x); } But not in this one: static void Main(string[] args) { try {

Java: what are IOEXceptions in BufferedReader's readLine() for?

天涯浪子 提交于 2020-01-01 03:22:18
问题 I can "fix" the below exception with a try-catch loop but I cannot understand the reason. Why does the part "in.readLine()" continuosly ignite IOExceptions? What is really the purpose of throwing such exceptions, the goal probably not just more side effects? Code and IOExceptions $ javac ReadLineTest.java ReadLineTest.java:9: unreported exception java.io.IOException; must be caught or declared to be thrown while((s=in.readLine())!=null){ ^ 1 error $ cat ReadLineTest.java import java.io.*;

MySQL - How to throw exception in stored procedure?

两盒软妹~` 提交于 2020-01-01 01:30:34
问题 How to generate an exception in the stored procedure in MySQL? For example: CREATE PROCEDURE SALES() BEGIN STATEMENT... STATEMENT... STATEMENT... IF (PRICE >= 500) THEN /** THROWS AN EXCEPTION.... WHAT DO TO STOP THE PROCEDURE. **/ END IF; STATEMENT... STATEMENT... STATEMENT... END; In MySQL I think there is no way to throw an exception in a stored procedure, but I can force an error by selecting from a non-existing table. For example: IF (PRICE > 500) THEN /*throw the error here*/ SELECT *

How to not throw a generically specified exception?

好久不见. 提交于 2020-01-01 01:16:10
问题 I created a "producer" interface (to be used with method references, respectively to be easily mocked for unit tests): @FunctionalInterface public interface Factory<R, T, X extends Throwable> { public R newInstanceFor(T t) throws X; } which I created like that, as my first use case actually had to throw some checked WhateverException . But my second use case doesn't have an X to throw. The best I could come up with to make the compiler happy is: Factory<SomeResultClass, SomeParameterClass,

Catching versus Throwing Exceptions in Java [duplicate]

て烟熏妆下的殇ゞ 提交于 2019-12-31 22:40:16
问题 This question already has answers here : When to catch the Exception vs When to throw the Exceptions? (8 answers) Closed 21 days ago . So I have two general questions about java in general. The first is when would one use a try/catch in the body of the method versus using throws exception in declaring the method? Here is a little demonstration of what I mean. This: public void whileChatting() throws IOException{} versus public void closeConnection() { try { } catch (IOException ioException) {

Servlet : SEVERE: Allocate exception for servlet

你说的曾经没有我的故事 提交于 2019-12-31 22:26:14
问题 The following stacktrace is what I get when i try to access a servlet, which seems running fine from Tomcat manager. 11 Sep, 2012 11:50:12 AM org.apache.catalina.core.ApplicationContext log INFO: Marking servlet LoginServlet as unavailable 11 Sep, 2012 11:50:12 AM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Allocate exception for servlet LoginServlet java.lang.Error: Unresolved compilation problems: The import javax.servlet cannot be resolved The import javax.servlet cannot

Servlet : SEVERE: Allocate exception for servlet

最后都变了- 提交于 2019-12-31 22:26:05
问题 The following stacktrace is what I get when i try to access a servlet, which seems running fine from Tomcat manager. 11 Sep, 2012 11:50:12 AM org.apache.catalina.core.ApplicationContext log INFO: Marking servlet LoginServlet as unavailable 11 Sep, 2012 11:50:12 AM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Allocate exception for servlet LoginServlet java.lang.Error: Unresolved compilation problems: The import javax.servlet cannot be resolved The import javax.servlet cannot

Try/catch blocks inside constructors

和自甴很熟 提交于 2019-12-31 22:04:27
问题 Is it a bad programming practice to have try/catch blocks inside constructors? Or does it make no difference as long as our programs handle typeinitializer exceptions gracefully. In C# if there are any exceptions inside a constructor the framework always throws typeinitilizer exceptions. Thanks, Shamika 回答1: System.TypeInitializationException is thrown when a static constructor throws an exception, not on an instance constructor. Exceptions are thrown normally in instance constructors. That