exception-handling

Handling Unsupported Types

∥☆過路亽.° 提交于 2019-12-13 00:13:03
问题 I am creating an array of data: var data = new Data[] { 1, "string", true, //.. }; //In this case, assume that strings and booleans are supported types, but integers are not. When I store the set of data, it runs through a series of if statements to store data: if (data is string) StoreData(data as string); else if (data is boolean) StoreData(data as boolean); //.. Because integers are not supported, I would like my code to handle it appropriately (whether it would be logging, etc.). However,

Laravel 5.3 Intervention/image NotReadableException using images from urls

心已入冬 提交于 2019-12-12 23:34:31
问题 How do I deal with the following error so that my script doesn't stop working when the exception occurs: NotReadableException in AbstractDecoder.php line 302: Image source not readable I've tried using the following ($file is the url of the image): // Return false if error try { $img = Image::make($file); } catch(NotReadableException $e) { return false; } This doesn't seem to catch the exception and return false. What else can I do? 回答1: You either need the full namespaced exception in the

Catch All (handled or unhandled) Exceptions

丶灬走出姿态 提交于 2019-12-12 23:12:24
问题 I want to catch all exceptions raised (handled or unhandled) to log them. for unhandled i use ThreadExceptionEventHandler and UnhandledExceptionEventHandler but i want to catch and exceptions that are in try catch block with or without (Exception e). It's possible to inherit the exceptions class to create a general event? 回答1: Inheriting from Exception to provide your own Exception class would work fine for exceptions you generate in your code, and you could use the inner exception

Spring. How exception translation works?

对着背影说爱祢 提交于 2019-12-12 22:18:30
问题 I have following code: @Repository public class UserDAOImpl implements UserDAO { public void addUser(User user) { throw new HibernateException("unchecked exception"); } } @Service public class UserServiceImpl implements UserService { @Autowired private UserDAO userDAO; @Override public void addUser(User user) { try { userDAO.addUser(user); } catch (Exception e) { e.printStackTrace(); } } } web.xml: <context:component-scan base-package="org.example.dao, org.example.services"/> <mvc:annotation

C# equivalent to Python's traceback library

半腔热情 提交于 2019-12-12 21:27:12
问题 In this post, python has traceback library to get some detailed error information (line number, file name ...). Does C# have similar functions to know what file/line number that generates the exception? ADDED I came up with the following code based on the answers. using System; // https://stackoverflow.com/questions/4474259/c-exception-handling-with-a-string-given-to-a-constructor class WeekdayException : Exception { public WeekdayException(String wday) : base("Illegal weekday: " + wday) {} }

Does Java handle exception automatically without using a try and catchblock?

半城伤御伤魂 提交于 2019-12-12 21:24:00
问题 This piece of code shows exception: Exception in thread "main" java.lang.ArithmeticException: / by zero at Ankit2.main(Ankit2.java:6) Why and how its happening? Without using try and catch block? class ankit1 { public static void main(String args[]) { float a=20,b=120,c=50,sum; sum=(a+b+c)/0; System.out.println("The average of three number is:"+sum); } } 回答1: That is a RuntimeException. You do not have to declare or catch those. Any exception that your code does not catch (declared or not),

How to catch a nested exception in java

大城市里の小女人 提交于 2019-12-12 20:28:16
问题 I'm using Apache Xalan (v.2.7.1) to translate XML to XHTML in Apache Tomcat (v6.0.32). Sometimes the loading gets cancelled by the client and the following exception is thrown: javax.xml.transform.TransformerException: org.apache.xalan.xsltc.TransletException: ClientAbortException: java.io.IOException at org.apache.xalan.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:636) at org.apache.xalan.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:303) ... I would like to catch

What is the right way to deal with exceptions in Castle Windsor's UsingFactoryMethod?

谁说我不能喝 提交于 2019-12-12 20:08:57
问题 I'm using the Nhibernate persistence facility from Windor's tutorial: Kernel.Register( Component.For<ISessionFactory>() .UsingFactoryMethod(config.BuildSessionFactory) .LifeStyle.Singleton, Component.For<ISession>() .UsingFactoryMethod(k => k.Resolve<ISessionFactory>().OpenSession()) .LifeStyle.PerWebRequest); Sometimes my call to config.BuildSessionFactory will fail (maybe my mappings are wrong, or my connection string is invalid or whatever). In the debugger, I can see the Nhibernate

An exception occurred during configuration of persistence layer

纵然是瞬间 提交于 2019-12-12 20:08:20
问题 I'm doing a project in Nhibernate with MySql in asp.net. In that while executing the code I got the error like An exception occurred during configuration of persistence layer in the below line ISessionFactory factory = new NHibernate.Cfg.Configuration().Configure).BuildSessionFactory(); So let me help to trouble shoot the error. Here s my Configuration file <?xml version="1.0" encoding="utf-8" ?> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <!-- an ISessionFactory

Error validating access token: The session is invalid because the user logged out

青春壹個敷衍的年華 提交于 2019-12-12 19:20:40
问题 My code: var fbWebContext = FacebookWebContext.Current; if (fbWebContext.IsAuthorized()) { var fb = new FacebookWebClient(fbWebContext); dynamic result = fb.Get("/me"); name.Text = result.name; } dynamic result = fb.Get("/me"); throws: (OAuthException) Error validating access token: The session is invalid because the user logged out. How should I change my code to prevent this? 回答1: You can ask for the "offline_access" extended permission. This will prevent this message and the user does not