159
160 try: # This only works on Linux
161 record('memUsage', getMemUsage())
162 except Exception:163 pass
164
165
144 if not settings.SKIP_TAGS_FOR_NONTAGGED or ';' in metric:
145 tagQueue.add(metric)
146 instrumentation.increment('creates')
147 except Exception as e:148 log.err()
149 log.msg("Error creating %s: %s" % (metric, e))
150 instrumentation.increment('errors')
168 if not settings.SKIP_TAGS_FOR_NONTAGGED or ';' in metric:
169 tagQueue.update(metric)
170 updateTime = time.time() - t1
171 except Exception as e:172 log.err()
173 log.msg("Error writing to %s: %s" % (metric, e))
174 instrumentation.increment('errors')
189 while reactor.running:
190 try:
191 writeCachedDataPoints()
192 except Exception:193 log.err()
194 # Back-off on error to give the backend time to recover.
195 time.sleep(0.1)
210 while reactor.running:
211 try:
212 writeTags()
213 except Exception:214 log.err()
215 # Back-off on error to give the backend time to recover.
216 time.sleep(0.1)
If the except block catches a very general exception, it is likely to catch any unrelated errors too. Try to be more explicit about which exception(s) you're trying to catch.
If you need to catch every other exception, then mark it as intentional by
adding a # skipcq
comment.
try:
x = a / b
except Exception:
x = a / (b + 1)
try:
line = input('Enter numbers:')
numbers = [int(i) for i in line.split()]
except BaseException:
print('Only use numbers for the input')
try:
x = a / b
except ZeroDivisionError:
x = a / (b + 1)
try:
event_loop.run()
except Exception as exc: # skipcq: PYL-W0703 - Loop can sometimes crash.
sentry.report(exc)
try:
line = input('Enter numbers:')
numbers = [int(i) for i in line.split()]
except ValueError:
print('Only use numbers for the input')