throw

T-SQL Throw Exception

北战南征 提交于 2019-11-30 07:50:40
I am facing the famous 'Incorrect syntax' while using a THROW statement in a T-SQL stored procedure. I have Googled it and checked the questions on StackOverflow but the solutions proposed (and strangely, accepted) do not work for me. I am modifying a stored procedure as follows: ALTER PROCEDURE [dbo].[CONVERT_Q_TO_O] @Q_ID int = NULL, @IDENTITY INT = NULL OUTPUT AS BEGIN SET NOCOUNT ON; DECLARE @EXISTING_RECORD_COUNT [int]; SELECT @EXISTING_RECORD_COUNT = COUNT (*) FROM [dbo].[O] WHERE [Q_ID] = @Q_ID IF @EXISTING_RECORD_COUNT = 0 BEGIN -- DO SOME STUFF HERE -- RETURN NEW ID SELECT @IDENTITY =

How to throw good exceptions?

无人久伴 提交于 2019-11-30 06:46:50
问题 I heard you should never throw a string because there is a lack of information and you'll catch exceptions you dont expect to catch. What are good practice for throwing exceptions? do you inherit a base exception class? Do you have many exceptions or few? do you do MyExceptionClass& or const MyExceptionClass& ? etc. Also i know exceptions should never been thrown in destructors i'll add that i understand design by contract and when to throw exception. I am asking how i should throw exceptions

Finally in C++

假如想象 提交于 2019-11-30 02:23:34
Is this a good way to implement a Finally-like behavior in standard C++? (Without special pointers) class Exception : public Exception { public: virtual bool isException() { return true; } }; class NoException : public Exception { public: bool isException() { return false; } }; Object *myObject = 0; try { // OBJECT CREATION AND PROCESSING try { myObject = new Object(); // Do something with myObject. } // EXCEPTION HANDLING catch (Exception &e) { // When there is an excepion, handle or throw, // else NoException will be thrown. } throw NoException(); } // CLEAN UP catch (Exception &e) { delete

Do I have to break after throwing exception?

五迷三道 提交于 2019-11-30 01:09:34
问题 I'm writing a custom class in C# and I'm throwing a couple exceptions if people give the wrong inputs in some of the methods. If the exception is thrown, will any of the code in the method after the throw still be executed? Do I have to put a break after the throw, or does a throw always quit the method? 回答1: When you throw an exception, the next code to get executed is any catch block that covers that throw within the method (if any) then, the finally block (if any). You can have a try, a

“rxjs” observable.throw is not a function - Angular4

微笑、不失礼 提交于 2019-11-29 22:13:43
I've been learning Angular 4 and everything was going smoothly until I tried to implement catch handling in a service. I'm trying to use "rxjs" catch and throw but I've got an undefined function error in my console. import { Injectable } from '@angular/core'; import { Http } from "@angular/http"; import { Observable } from 'rxjs/observable'; import 'rxjs/add/operator/catch'; import 'rxjs/add/observable/throw'; import { AppError } from "../app/common/app.error"; import { NotFoundError } from "../app/common/not-found-error"; import { BadInput } from "../app/common/bad-input"; @Injectable()

Does adding parentheses around a throw argument have any effect?

佐手、 提交于 2019-11-29 14:41:55
Is there a difference in writing: throw SomeException; and throw(SomeException); I have seen some sources that claim the latter (with parentheses) is not a good option for some reason but alas I can not recall where I've seen this. iammilind There should not be any functionality difference between the two expressions apart from the parentheses. I have never heard of any clear reason that says why one should be superior to the other. To me the first option looks more intuitive as it does not include the unnecessary parentheses! Also as @Pubby said in the comment, one should not confuse with the

How to throw an error in MySql procedure?

末鹿安然 提交于 2019-11-29 13:18:24
What is the mechanism to force the MySQL to throw an error within the stored procedure? I have a procedure which call s another function: PREPARE my_cmd FROM @jobcommand; EXECUTE my_cmd; DEALLOCATE PREPARE my_cmd; the job command is: jobq.exec("Select 1;wfdlk# to simulatte an error"); then: CREATE PROCEDURE jobq.`exec`(jobID VARCHAR(128),cmd TEXT) BEGIN DECLARE result INT DEFAULT 0; SELECT sys_exec( CONCAT('echo ',cmd,' | base64 -d > ', '/tmp/jobq.',jobID,'.sh ; bash /tmp/jobq.',jobID,'.sh &> /tmp/jobq.',jobID)) INTO result; IF result>0 THEN # call raise_mysql_error(result); END IF; END; My

PHP Fatal error: Uncaught exception 'Exception'

雨燕双飞 提交于 2019-11-29 09:48:20
I'm playing around with exceptions in PHP. For example, I have a script that reads a $_GET request and loads a file; If the file doesn't exists, an new exception should be thrown: if ( file_exists( $_SERVER['DOCUMENT_ROOT'] .'/'.$_GET['image'] ) ) { // Something real amazing happens here. } else { throw new Exception("The requested file does not exists."); } The problem is that, when I try to supply an non existent file for the test, I got a 500 error instead of the exception message. The server log is the following: [09-Jul-2013 18:26:16 UTC] PHP Fatal error: Uncaught exception 'Exception'

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

狂风中的少年 提交于 2019-11-29 08:08:47
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; } 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() . It specifies that any std::exception can be thrown from func() , and nothing else. If something else is thrown, it will call an unexpected() function which by

Strange debugger behaviour in async method

随声附和 提交于 2019-11-29 08:06:56
When I stepped over breakpoints in my code I have encountered strange behaviour of debugger: public async Task DoSomeWork() { await Task.Run(() => { Thread.Sleep(1000); }); var test = false; if (test) { throw new Exception("Im in IF body!"); } } Debugger goes into if body. It's remarkable that the exception is not really thrown but just looks like it is. So you can't reproduce that if you place breakpoint right on throw . You must place it above and step down to the if body to catch it. The same works on any kind of exception instance (as well as explicit null ) and even on return instead of