Posts

Showing posts with the label Exception

Catch Multiple Exceptions In One Line (except Block)

Answer : From Python Documentation: An except clause may name multiple exceptions as a parenthesized tuple, for example except (IDontLikeYouException, YouAreBeingMeanException) as e: pass Or, for Python 2 only: except (IDontLikeYouException, YouAreBeingMeanException), e: pass Separating the exception from the variable with a comma will still work in Python 2.6 and 2.7, but is now deprecated and does not work in Python 3; now you should be using as . How do I catch multiple exceptions in one line (except block) Do this: try: may_raise_specific_errors(): except (SpecificErrorOne, SpecificErrorTwo) as error: handle(error) # might log or have some other default behavior... The parentheses are required due to older syntax that used the commas to assign the error object to a name. The as keyword is used for the assignment. You can use any name for the error object, I prefer error personally. Best Practice To do this in a manner currently and ...

ASP.NET Custom Error Page - Server.GetLastError() Is Null

Image
Answer : Looking more closely at my web.config set up, one of the comments in this post is very helpful in asp.net 3.5 sp1 there is a new parameter redirectMode So we can amend customErrors to add this parameter: <customErrors mode="RemoteOnly" defaultRedirect="~/errors/GeneralError.aspx" redirectMode="ResponseRewrite" /> the ResponseRewrite mode allows us to load the «Error Page» without redirecting the browser, so the URL stays the same, and importantly for me, exception information is not lost. OK, I found this post: http://msdn.microsoft.com/en-us/library/aa479319.aspx with this very illustrative diagram: (source: microsoft.com) in essence, to get at those exception details i need to store them myself in Global.asax, for later retrieval on my custom error page. it seems the best way is to do the bulk of the work in Global.asax, with the custom error pages handling helpful content rather than logic. A combination of w...