To avoid writing multiple try catch async await in a function, a better option is to create a function to wrap each try catch. The first result of the promise returns an array where the first element is the data and the second element is an error. And if there's an error, then the data is null and the error is defined.
AVOID empty catch blocks. In general, empty catch blocks should be avoided. In cases where they are intended, a comment should be provided to explain why exceptions are being caught and suppressed. Alternatively, the exception identifier can be named with underscores (e.g., _ ) to indicate that we intend to skip it.
When you have methods that do multiple things you are multiplying the complexity, not adding it. In other words, a method that is wrapped in a try catch has two possible outcomes. You have the non-exception outcome and the exception outcome.
To catch exceptions the moment they're thrown ("first-chance exceptions" in Win32 parlance):
in VS2008: go to Debug, Exceptions...
by VS2015: this has been moved to Debug > Windows > Exception Settings
Then check the box Thrown for Common Language Runtime Exceptions.
There is no way to deactivate try/catch blocks.
However, for debug purposes, if you want to break as soon as a particular type of exception is thrown, you can get Visual Studio to do that (Debug -> Exceptions; select the exception type you're interested in and check the "Thrown" box).
Thought about this today and found an other solution. The advantage of this is that the IDE will stop at the exact point of the occuring exception.
Somewhere globaly defined:
Namespace Global.System
Public Class NeverOccurException
Inherits Exception
End Class
End Namespace
At the beginning of each source code file:
#If DEBUG
Imports CatchAtReleaseException = System.NeverOccurException
#Else
Imports CatchAtReleaseException = System.Exception
#End If
Usage:
'Compiled in DEBUG-Mode the TryCatch is "disabled", because the
'the ALIAS CatchAtReleaseException is set to "NeverOccurException"
'Compiled as RELEASE the TryCatch is "enabled", because the ALIAS
'is set to the regular "System.Exception"
Public Sub SampleSub()
Try
'...
Catch ex As CatchAtReleaseException
End Try
End Sub
Have fun with it, Greetings, Ted
If you want to do in the IDE, Debug -> Exceptions is the dialog where you can ask the IDE to break when a specific/category/all exceptions are thrown.
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