Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differentiate thrown SqlExceptions

I need to separate database access error (like wrong username) from database query error (like select insert..column not exist etc.). They will both throw SqlException. But I want my program to continue when a query error is thrown but and shut down when an access error is thrown.

How can I separate these two errors? Write my own exception?

like image 644
LIU Avatar asked Nov 24 '25 02:11

LIU


1 Answers

I suggest checking the Number propery of the SqlException.

See my answer to SqlException catch and handling

like image 200
Richard Schneider Avatar answered Nov 26 '25 16:11

Richard Schneider



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!