Sub process1()
try
...
Process2()
...
catch (ex as exception)
throw new Exception("[process01]" & ex.message)
end try
End Sub
Sub Process2
try
...
catch (ex as Exception)
throw new Exception("[process02]" & ex.Message())
End Try
End Sub
...
Public Sub Main(ByVal args() As String)
try
...
process1()
catch (ex As Exception)
Console.Writeline(ex.Message())
End Try
In the example above, if an error happens in Process2, it will be thrown upwards until it reaches the main subroutine. So when you see the error message, you know that the error was encountered in Process2. You will then see the error as
[process1][Process2]...
I found this makes it easier to zoom into the errors in my application. This concept can be used in Console applications, Web Applications and Windows Application. Just need to make sure that the message is displayed somewhere.
No comments:
Post a Comment