exception

Java exception must be caught or declared to be thrown [duplicate]

主宰稳场 提交于 2019-12-25 04:35:18
问题 This question already has answers here : Java unreported exception (2 answers) Closed 3 years ago . I am trying to learn Java networking using this manual - http://duta.github.io/writing/StartingNetworking.pdf Why do I get “must be caught or declared to be thrown” at this line (it is ServerSocket part of the manual). Why the code in the manual is assumed to be working, but mine doesn't? Socket socket = serverSocket.accept(); Complete code: public class ChatServer { public static void main(){

How to supress the creation of an (.net) Exception object?

做~自己de王妃 提交于 2019-12-25 04:34:12
问题 If I do not care about a thrown Exception. Can I code in a way as not to create it? In other words, can an Exception be thrown but no Exception object be created? An example - Simple example using a System.Net.Sockets.Socket Socket acceptingSocket; acceptingSocket.Blocking = false; while(condition) { try { Socket acceptedSocket = acceptingSocket.Accept(); //(i) doWork(acceptedSocket); } catch{} } because the socket is in non-blocking mode if there is no connection to accept a SocketException

How to supress the creation of an (.net) Exception object?

家住魔仙堡 提交于 2019-12-25 04:34:02
问题 If I do not care about a thrown Exception. Can I code in a way as not to create it? In other words, can an Exception be thrown but no Exception object be created? An example - Simple example using a System.Net.Sockets.Socket Socket acceptingSocket; acceptingSocket.Blocking = false; while(condition) { try { Socket acceptedSocket = acceptingSocket.Accept(); //(i) doWork(acceptedSocket); } catch{} } because the socket is in non-blocking mode if there is no connection to accept a SocketException

Attempt to invoke interface method 'int android.database.Cursor.getCount()' on a null object reference

主宰稳场 提交于 2019-12-25 04:29:12
问题 I do have a problem that gives me a headache. I store some images of my city in the sqlite database via a custom content provider. However when I run my app I get a null cursor. Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'int android.database.Cursor.getCount()' on a null object reference at theo.testing.androidcustomloaders.fragments.MainActivityFragment.onActivityCreated(MainActivityFragment.java:74) at android.support.v4.app.Fragment.performActivityCreated

MethodAccessException with Reflection on Windows Phone 7

醉酒当歌 提交于 2019-12-25 04:14:17
问题 While working with reflection, I recently got to the point where I wanted to access an object (in fact, a static instance of an object). The object itself is defined by an internal class, therefore there is no other way to access it. Instead of directly getting a parametrized constructor, I can access a static instance via the Instance property. With the help of reflection, I am also able to get this property and set it to a PropertyInfo instance - it is detected correctly. However, I am not

Calling IOS::exception(…) causes EOF to throw InteropServices.SEHException from std::getline(…) in C++-CLI, why?

廉价感情. 提交于 2019-12-25 03:55:30
问题 I run the following function to load a file. It is being ported from CLI to standard C++ and exhibits unexpected behaviour when I attempt to specify that I would like to throw all exceptions except EOF. bool parseFile(ManagedClass *%parsedFileAsManagedObject, const string &fileName); std::string line; bool success = true; ifstream is(fileName.c_str()); //Unless I comment out the following line I get problems is.exceptions( ifstream::badbit | ifstream::failbit ); //do stuff try { while

Scanner Class InputMismatchException and Warnings

江枫思渺然 提交于 2019-12-25 03:47:25
问题 I am having trouble running this program. The program takes an expression such as "A = 7" and puts the variable A (String) and the number 7 in a Map container. I'm not if i'm not parsing the string correctly which is causing the error or for some other reason. Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Scanner.java:909) at java.util.Scanner.next(Scanner.java:1530) at java.util.Scanner.nextInt(Scanner.java:2160) at java.util.Scanner.nextInt

How to know what exceptions to rescue

删除回忆录丶 提交于 2019-12-25 03:47:15
问题 I want a class that will load and save settings in yaml file, and displays an error if something happens. I must catch exceptions and I must know what to catch. There is no guarantee what exception will be raised; user might press CTRL+C or memory may run out, but YAML.load_file can raise only a limited number of exceptions. There is nowhere listed what exceptions a function YAML.load_file might raise. How can I catch only them when I don't know what those exceptions are? This question has

Exception with String argument, why is this happening?

丶灬走出姿态 提交于 2019-12-25 03:27:06
问题 I have : Dim con As New OleDbConnection(My.Resources.ConnectionString) // Give exception = Format of the initialization string does not conform to specification starting at index 62. When I substitute the actual value of the Resource, it give no exception : Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\rawData.xlsx;Extended Properties=""Excel 12.0 XML;""") The value of ConnectionString in Resources : <data name="ConnectionString" xml:space="preserve"> <value

Disable Visual Basic Err object while debugging

拜拜、爱过 提交于 2019-12-25 03:01:12
问题 I have a windows service written in VB.NET and for error logging at runtime it uses the Err object of Visual Basic. When I am debugging the service it is not giving me any error but at the same time it is setting the Err object with number 13 which means I have a type mismatch somewhere (According to Error List) Any idea how I can forcefully throw the runtime exception while debugging? I have tried commenting the below code but no luck:- On Error Resume Next 回答1: You can use Err.Raise()