I need to know what is better (for performance and else), Using Try Catch when expecting error and there is no alternate scenario when error hapened or check the value first ?
For Example (VB.net): If I need to fill text box by value from database (from Data Reader for example), and I expecting some null values, and if value is null I will leave textbox empty.
now I have to ways to do this:
try
textbox1.text = DR("Name")
catch
end try
now if column Name contain null value the error will raise and textbox1 still empty.
If Not IsDBNull(DR("Name")) Then textbox1.Text = DR("Name")
what is better ?
Thank you so much.
Do not use exception handling as flow control. Ever.
So - check the value instead of Try/Catch.
When an exception is thrown the runtime has quite a lot of work to do - if you expect null values - always check for them instead of relying on exceptions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With