Answered by:
try ...catch

Question
-
hali
van egy olyan amitol sirok
create
proc probaas
begin
try print 'futok...' create table #t (a int, b int) update #t set c = 7end
trybegin
catch print 'Hiba van'end
catchgo
exec
probaezt miert NEM kapja el a catch?
ha beirok az update ele egy select 1/0-t azt megfogja, mindket hiba severity 16, state 1-es.
nem ertem
akkor most muxik ez a try-catch vagy nem muxik?
Monday, April 23, 2007 8:38 AM
Answers
-
Szintaktikai hibákra nem kell lefutnia:
Link: http://msdn2.microsoft.com/en-us/library/ms175976.aspx
Errors Unaffected by a TRY…CATCH Construct
TRY…CATCH constructs do not trap the following conditions:
- Warnings or informational messages that have a severity of 10 or lower.
- Errors that have a severity of 20 or higher that stop the SQL Server Database Engine task processing for the session. If an error occurs that has severity of 20 or higher and the database connection is not disrupted, TRY…CATCH will handle the error.
- Attentions, such as client-interrupt requests or broken client connections.
- When the session is ended by a system administrator by using the KILL statement.
The following types of errors are not handled by a CATCH block when they occur at the same level of execution as the TRY…CATCH construct:
- Compile errors, such as syntax errors, that prevent a batch from running.
- Errors that occur during statement-level recompilation, such as object name resolution errors that occur after compilation because of deferred name resolution.
These errors are returned to the level that ran the batch, stored procedure, or trigger.
If an error occurs during compilation or statement-level recompilation at a lower execution level (for example, when executing sp_executesql or a user-defined stored procedure) inside the TRY block, the error occurs at a lower level than the TRY…CATCH construct and will be handled by the associated CATCH block. For more information, see Using TRY...CATCH in Transact-SQL.
The following example shows how an object name resolution error generated by a SELECT statement is not caught by the TRY…CATCH construct, but is caught by the CATCH block when the same SELECT statement is executed inside a stored procedure.
USE AdventureWorks; GO BEGIN TRY -- Table does not exist; object name resolution -- error not caught. SELECT * FROM NonexistentTable; END TRY BEGIN CATCH SELECT ERROR_NUMBER() as ErrorNumber, ERROR_MESSAGE() as ErrorMessage; END CATCH
Safi
Monday, April 23, 2007 5:57 PMModerator - Warnings or informational messages that have a severity of 10 or lower.
All replies
-
Szintaktikai hibákra nem kell lefutnia:
Link: http://msdn2.microsoft.com/en-us/library/ms175976.aspx
Errors Unaffected by a TRY…CATCH Construct
TRY…CATCH constructs do not trap the following conditions:
- Warnings or informational messages that have a severity of 10 or lower.
- Errors that have a severity of 20 or higher that stop the SQL Server Database Engine task processing for the session. If an error occurs that has severity of 20 or higher and the database connection is not disrupted, TRY…CATCH will handle the error.
- Attentions, such as client-interrupt requests or broken client connections.
- When the session is ended by a system administrator by using the KILL statement.
The following types of errors are not handled by a CATCH block when they occur at the same level of execution as the TRY…CATCH construct:
- Compile errors, such as syntax errors, that prevent a batch from running.
- Errors that occur during statement-level recompilation, such as object name resolution errors that occur after compilation because of deferred name resolution.
These errors are returned to the level that ran the batch, stored procedure, or trigger.
If an error occurs during compilation or statement-level recompilation at a lower execution level (for example, when executing sp_executesql or a user-defined stored procedure) inside the TRY block, the error occurs at a lower level than the TRY…CATCH construct and will be handled by the associated CATCH block. For more information, see Using TRY...CATCH in Transact-SQL.
The following example shows how an object name resolution error generated by a SELECT statement is not caught by the TRY…CATCH construct, but is caught by the CATCH block when the same SELECT statement is executed inside a stored procedure.
USE AdventureWorks; GO BEGIN TRY -- Table does not exist; object name resolution -- error not caught. SELECT * FROM NonexistentTable; END TRY BEGIN CATCH SELECT ERROR_NUMBER() as ErrorNumber, ERROR_MESSAGE() as ErrorMessage; END CATCH
Safi
Monday, April 23, 2007 5:57 PMModerator - Warnings or informational messages that have a severity of 10 or lower.
-
igen ezt megtalaltam en is.
bar szamomra erthetetlen, hogy miert alkalmazaz MS felmegoldasokat
hiszen miert ne lehetne, hogy erre is mukodjon?
Tuesday, April 24, 2007 9:00 AM