|
| 1 | +# Copyright 2016 Google Inc. All rights reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | + |
| 16 | +# [START error_reporting] |
| 17 | +# [START error_reporting_quickstart] |
| 18 | +# [START error_reporting_setup_python] |
| 19 | +def simulate_error(): |
| 20 | + from google.cloud import error_reporting |
| 21 | + |
| 22 | + client = error_reporting.Client() |
| 23 | + try: |
| 24 | + # simulate calling a method that's not defined |
| 25 | + raise NameError |
| 26 | + except Exception: |
| 27 | + client.report_exception() |
| 28 | +# [END error_reporting_setup_python] |
| 29 | +# [END error_reporting_quickstart] |
| 30 | +# [END error_reporting] |
| 31 | + |
| 32 | + |
| 33 | +# [START error_reporting_manual] |
| 34 | +# [START error_reporting_setup_python_manual] |
| 35 | +def report_manual_error(): |
| 36 | + from google.cloud import error_reporting |
| 37 | + |
| 38 | + client = error_reporting.Client() |
| 39 | + client.report("An error has occurred.") |
| 40 | +# [START error_reporting_setup_python_manual] |
| 41 | +# [END error_reporting_manual] |
| 42 | + |
| 43 | + |
| 44 | +if __name__ == '__main__': |
| 45 | + simulate_error() |
| 46 | + report_manual_error() |
0 commit comments