C#: Exception handling in recursive call -


I have recursive method calls when an exception is thrown, so I want to see where this happened in the recursive call stack . I have an area in which there is a "path" that represents the recurring stack.

Now I would like to add path information to any exceptions that might possibly be put in a recursive call.

Maintain zero recurring (int x) // // recursive path information path. Push (x); Try {// some stuff and recursively call the rearranging method (x + 6); } Hold (Exception preceding) {If (formerly RecursionException is) {// Exception is already wrapped; } // wrap the exception, it should only be done once // save the path and original exception to the wrapper adopt new recycling (path.tostring (), pre); } Finally maintain the {// recursive path information path. POP ()}}

It looks very complex, there is not only one way


edit

: To indicate this: I would like a very simple situation, where there are no such overheads to call this method continuously, because I have a lot of recursive calls, there is only one Not the way, two ways to call each other repeatedly, which is quite complex.

That is why I would like to try to hold the whole block, but I can not see any solution for this.

It is not a big problem for the exceptions put in my code, because it may involve path from the beginning but this is a problem with every other exception.


Edit : Exception should be wrapped in any other code, not only when calling the recurring method:

  try {Int a = 78 / x; // DivisionByZeroExeption Recurrence (x + 6); This.NullReference.Add (x); // NullReferenceException}  

does not work just by calling the ReikiConnect.

There are many ways, different signatures, different things, the only thing exception handling is.

I am trying to include the recursive path in exception descriptions to assist with debugging

About trying it.

  Hold the public zero recursive (int x) {try {_Recursive (x)} (new recursionException {path.ToString (), ex); The obvious path, we know that we are at the top at this point}} Private Zero _ sequence (int x) {// Maintain the path of the path of the recursive path. Push (x); _Recursive (x + 6); // Keep recurring path alert // Note that this is not in the catch, if the exception is not the route then the call will not be made. Pop ()}  

If you are using threading etc., you need to store the thread in the local storage.


If you do not want to force your collar to deal with the Rickaceian exception, then you can use the "paths" public therefore the collar can use it. (As Eric Lipert answers later)

Or while catching the exception you can log the path of your error logging system and then throw the exception again

  Public Zero Recursive (int x) {try {_Recursive (x)} hold {// log in path of your loggin sysem // Perhaps log in exception if you are not logging />> / Code> 

The advantage of this is that the caller does not have to "know about" the path "absolutely Also. All this comes in accordance with the need of your caller, somehow I think that you are a collar for this code, so we do not have any idea what is required for this level.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -