exception-handling

PHP check thrown exception type

情到浓时终转凉″ 提交于 2019-12-18 18:42:13
问题 Of course in PHP you can catch all thrown exceptions with: try{ /* code with exceptions */ }catch(Exception $e) { /* Handling exceptions */ } But is there a way to check the exception type of the thrown exception from inside the catch block? 回答1: You can use get_class: try { throw new InvalidArgumentException("Non Sequitur!", 1); } catch (Exception $e) { echo get_class($e); } 回答2: You can have multiple catch blocks to catch different Exception types. See below: try { /* code with exceptions *

PHP check thrown exception type

半腔热情 提交于 2019-12-18 18:42:02
问题 Of course in PHP you can catch all thrown exceptions with: try{ /* code with exceptions */ }catch(Exception $e) { /* Handling exceptions */ } But is there a way to check the exception type of the thrown exception from inside the catch block? 回答1: You can use get_class: try { throw new InvalidArgumentException("Non Sequitur!", 1); } catch (Exception $e) { echo get_class($e); } 回答2: You can have multiple catch blocks to catch different Exception types. See below: try { /* code with exceptions *

Can Delphi tell me the name of the routine that threw an exception?

こ雲淡風輕ζ 提交于 2019-12-18 18:28:17
问题 I know how to catch exceptions in delphi (try..except/finally and e.message) but I want to know if there exists an exception handling mechanism which can raise the exception and also the name of the routine which raised it. by example procedure/function bla();//this can be in a unit/class begin code.... an error is raised here -> inside or not of an try-except/finally block end; and I'll receive an message/object/anything that indicates me that error 'x' was raised in 'bla'. I know about

Pattern for implementing sync methods in terms of non-parallel Task (Translating/Unwrapping AggregateExceptions)

旧街凉风 提交于 2019-12-18 16:51:07
问题 I have an Async method returning a Task. I also wish to offer a synchronous equivalent, but I don't want consumers of it to have to go unpacking AggregateException s. Now I understand that the whole idea is that you couldn't arbitrarily pick one in a general way, and I know I could go read loads more Stephen Toub articles (I will, but not now) and I'll understand it all and can decide for myself. In the interim, I want to use the fact that my tasks are actually just chained 'workflows'

MSTest Test Context Exception Handling

£可爱£侵袭症+ 提交于 2019-12-18 16:17:27
问题 Is there a way that I can get to the exception that was handled by the MSTest framework using the TestContext or some other method on a base test class? If an unhandled exception occurs in one of my tests, I'd like to spin through all the items in the exception.Data dictionary and display them to the test result to help me figure out why the test failed (we usually add data to the exception to help us debug in the production env, so I'd like to do the same for testing). Note: I am not testing

How to configure spring HandlerExceptionResolver to handle NullPointerException thrown in jsp?

南楼画角 提交于 2019-12-18 15:17:14
问题 From a jsp is thrown a NullPointerException for example using <% null.toString(); %> This exception is not handled by the HandlerExceptionResolver, but thrown to the web container(tomcat) and converted into a code 500 error . How can I configure spring to get that error in my HandlerExceptionResolver ? Details: Spring can be configured to handle exceptions thrown inside Controllers, but not exceptions thrown by view. Of course i can resolve the NullPointerException, but i want to design a

Filter on exception text in elmah

╄→гoц情女王★ 提交于 2019-12-18 13:39:13
问题 Is there a way to filter exceptions in elma using the exception message? Examples: "System.Web.HttpException: Request timed out." I don't want to filter out all HttpException, but only the timed-out requests. "System.Web.HttpException: Maximum request length exceeded." What I don't want to do is write own code for that. So is it possible to do this with the buildin-web.config configuration? Thank you! 回答1: Yes you can. Just use a regular expression to interrogate the message. See the example

How to catch exception thrown from library in GCC C++?

北战南征 提交于 2019-12-18 13:37:59
问题 When i use dlopen to dynamically load a library it seems i can not catch exceptions thrown by that library. As i understand it it's because dlopen is a C function. Is there another way to dynamically load a library that makes it possible to catch exceptions thrown by the lib in GCC? In Windows you can use LoadLibrary but for Linux i have only found dlopen but when using dlopen i can not catch exceptions. Edit : I have tried void* handle = dlopen("myLib.so", RTLD_NOW | RTLD_GLOBAL); and I

How do I trap a SerializationException in Web API?

∥☆過路亽.° 提交于 2019-12-18 13:19:23
问题 I have an ASP.NET Web API web service which throws a SerializationException in certain circumstances. The problem is that I'm unable to trap and log this exception server-side -- the only place it shows up is in the body of the HTTP response to the client. I registered an ExceptionFilterAttribute as described in Exception Handling in ASP.NET Web API and verified that it works properly when I throw an exception within my controller. Unfortunately the SerializationException is being thrown

Capture Arbitrary Conditions with `withCallingHandlers`

我们两清 提交于 2019-12-18 13:14:35
问题 The Problem I'm trying to write a function that will evaluate code and store the results, including any possible conditions signaled in the code. I've got this working perfectly fine, except for the situation when my function (let's call it evalcapt ) is run within an error handling expression. The problem is that withCallingHandlers will keep looking for matching condition handlers and if someone has defined such a handler outside of my function, my function loses control of execution. Here