Program Exception: sequence contains no elements. First, we thought of the sequence objects used in the Oracle database. The results were not exceeded. nextval and. currval were normal. Google, the exception is iquerable <t>. the first () method reports that when the query result set is empty, the first () method is called to report this exception. If the firstordefault () method is used, no exception is reported and the problem is resolved. Thought 1: When searching in Google, the keyword used at the beginning is "sequence contains no element" with double quotation marks. This is an exception message sent from a colleague over the phone, this keyword cannot be used to find valuable information. When I reproduce this exception at the site, I directly copied the exception text to Google for search, in this case, the keyword is "sequence contains no elements" with double quotation marks, and the problem is located immediately. The two keywords are only the difference between the singular and plural values of "element" and "elements.
This is unexpected. As a general idea, "element" should find more results than "elements". webpages containing "elements" should be a subset of "element. Does Google have the syntax analysis function in English?
Think 2: when calling the void method in a program, you often need to know whether the method is successfully executed. If it is not successful, you need to know the cause of the failure (usually an exception message ). For example, the method to be executed is fooa (). One of fooa's implementation methods is to throw an exception when it fails. The caller will naturally know that fooa fails to execute when an exception is caught, the cause of the failure is also obtained. However, I often use a method that does not throw an exception, but uses Boolean return values true and false to indicate success or failure. An out string parameter is added to carry the message at the time of failure. The two advantages of this solution are as follows: first, it avoids a lot of resources to be consumed when handling exceptions, and second, it can continue subsequent processing when processing failure occurs multiple times, the caller does not handle any exceptions. Code The program jumps out of execution when an exception occurs. Iquerable <t>. first and firstordefault methods. I want to write more fooaordefault methods, so that the caller can call fooa when handling exceptions. If they do not want to handle exceptions or avoid being affected by exceptions, call the fooaordefault method during execution.