Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std.conv, std.stdio, std.exception;
- void main(string[] args) {
- enforce(args.length > 1, "Usage: foo.exe filename");
- double[] nums;
- // Process a text file with one number per line into an array of doubles,
- // ignoring any malformed lines.
- foreach(line; File(args[1]).byLine()) {
- try {
- nums ~= to!double(line);
- } catch(ConvError) {
- // Ignore malformed lines.
- }
- }
- // Do stuff with nums.
- }
- boolean isNonZeroNumber = false;
- try {
- if(StringUtils.isNotBlank(s) && new BigDecimal(s).compareTo(BigDecimal.ZERO) != 0) {
- b = true;
- }
- } catch(NumberFormatException e) {
- //swallow this exception; b stays false.
- }
- return b;
- try {
- bytes[] hw = "Hello World".getBytes("UTF-8");
- }
- catch(UnsupportedCodingException e) {
- }
- import util.control.Exception.ignoring
- val numStrings = Array("a", "2", "5")
- for(a <- numStrings) {
- ignoring(classOf[NumberFormatException]) {
- println(a.toInt)
- }
- }
- 2
- 5
- try
- {
- DoSomething(); //This should throw exception if everything works well
- Assert.Fail('Expected exception was not thrown');
- }
- catch(<whatever exception>)
- {
- //Expected to get here
- }
- /* Check if the process is still alive; exitValue() throws an exception if it is */
- try {
- p.exitValue();
- processPool.remove(p);
- }
- catch (IllegalThreadStateException e) { /* expected behaviour */ }
- try
- {
- doWork();
- }
- catch(BenignException x)
- {
- _log.Debug("Error doing work: " + x.Message);
- }
- try
- {
- // execution code here
- }
- catch(Exception e)
- {
- // do nothing here
- }
- finally
- {
- // close db connection
- // close file io resource
- // close memory stream
- // etc...
- }
- this.currentDate = new Date();
- try {
- this.currentDate = $.datepicker.parseDate(this.options.hiddenDateFormat, this.element.val());
- } catch(_) {}
- // If an exception happens, it doesn't matter. Log the initial value or the new value
- function logId(person) {
- let id = 'No ID';
- try {
- id = person.data.id;
- } catch {}
- console.log(id);
- }
- function getter(obj){}
- function objChecker()
- {
- try
- {
- /* Check argument length and constructor type */
- if (getter.length === 1 && getter.constructor === Function)
- {
- console.log("Correct implementation");
- return true;
- }
- else
- {
- console.log("Wrong implementation");
- return false;
- }
- }
- catch(e)
- {
- return NaN;
- }
- finally
- {
- console.log(JSON.stringify(getter))
- }
- }
- // Test the override of the getter method
- getter = getter;
- objChecker();
- getter = [];
- objChecker();
- getter = {};
- objChecker();
- getter = RegExp;
- objChecker();
- getter = Function;
- objChecker();
Add Comment
Please, Sign In to add comment